Can you build me a xlsx parser in python to get the cell color of each cell?
- User
Can you build me a xlsx parser in python to get the cell color of each cell?
- Assistant
Sure, you can use the openpyxl library to read .xlsx files and parse the cell color. Here's a simple example of how you can do it:
from openpyxl import load_workbook from openpyxl.styles import PatternFill def get_cell_color(file_path, sheet_name): workbook = load_workbook(filename=file_path) sheet = workbook[sheet_name] cell_colors = {} for row in sheet: for cell in row: if cell.fill.start_color.index != '00000000': # Default color (no color) cell_colors[cell.coordinate] = cell.fill.start_color.index return cell_colors file_path = 'your_file.xlsx' sheet_name = 'Sheet1' print(get_cell_color(file_path, sheet_name))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.