简体   繁体   English

如何从excel文件和python中具有复杂表结构的数据中读取和识别颜色编码数据(字体和背景)?

[英]How to read and identify color coded data(font and background) from excel file and data with complex table structure in python?

I have an excel file that is conditionally formatted.我有一个条件格式的excel文件。 It has different values for different font colours as well as cell background colours.对于不同的字体颜色以及单元格背景颜色,它具有不同的值。 How to identify this information?如何识别这些信息? Additionally, the table structure is complex.此外,表结构很复杂。 Means single row header may contain merged cells/multiple values.意味着单行标题可能包含合并的单元格/多个值。 Example:例子: 在此处输入图片说明

Please help.请帮忙。 Thank you谢谢

使用 openpyxl 您可以读取 rgb 十六进制类型的基本颜色,但您需要检查 python 和 openpyxl 并且该库处于开发阶段

from openpyxl import load_workbook wb = load_workbook(filename='testfile.xlsx', read_only=True) worksheet = wb.active print(worksheet['A1'].font.color)

Please check the following and xlrd package, it will help you to solve your question.请检查以下和 xlrd 包,它将帮助您解决您的问题。

 excelbook = xlrd.open_workbook("excel urt", formatting_info=True)
excel_sheets = excelbook.sheet_names()
for item, exsh in enumerate(excel_sheets):
excel_sheet = excelbook.sheet_by_index(item)
rows, cols = excel_sheet.nrows, excel_sheet.ncols
for row in range(rows):
for col in range(cols):
thecell = excel_sheet.cell(row, col)      
xfx = excel_sheet.cell_xf_index(row, col)
xf = excelbook.xf_list[xfx]
bgx = xf.background.pattern_colour_index
print bgx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM