使用python:openpyxl或任何其他库来读取excel表格中单元格的颜色

好的,这里是我需要帮助,我有一个Excel表,我已经使用了图案填充,可以在下面的图片中看到。 所以我想要在python脚本中做的基本上是读取每一行,以检查单元格是否有模式填充,如果它确实使用在这些特定的单元格中find的值做一些事情。 我已经设法做了第一部分是用openpyxl来读取excel表格。

patternfill

我到目前为止所做的代码示例是这样的。 我只需要填写step3:if()部分,如果我需要导入另一个库是好的只是让我知道我需要做的:)

from openpyxl import load_workbook #Step 3: Use this function to read the colours and do something def postDialog(A, B, C, D, E, F, G, H, I, J, K, L): if (A == redcolorfill): #HERE How to read pattern fill color of cell #Step 1: Execute open excel workbook ACTION1_File = load_workbook('Myfile.xlsx', ) ACTION1_File_Sheet = ACTION1_File.get_sheet_names()[1] ACTION1_File_Sheet_Name = ACTION1_File.get_sheet_by_name(ACTION1_File_Sheet) #Step 2: For every row read columns AL and use in function postDialog for line in ACTION1_File_Sheet_Name.iter_rows(): #Columns A - L postDialog(line[0].value, line[1].value, line[2].value, line[3].value, line[4].value, line[5].value, line[6].value, line[7].value, line[8].value, line[9].value, line[10].value, line[11].value) 

这里是如何读取单元格的填充颜色

 for line in ACTION1_File_Sheet_Name.iter_rows(): for c in line: print(c.fill.bgColor) 

编辑:如何阅读一个特定的范围

 for c in ACTION1_File_Sheet_Name["A1:A10"]: print(c[0].fill.fgColor)