Openpyxl - 检查单元格是否已填充
问题描述:
我正在尝试检查单元格是否以黄色突出显示.我遇到的所有帖子都是填充一个单元格,而不是检查它是否有填充.到目前为止,这是我的代码:
I am trying to check if a cell is highlighted in yellow. All the posts I've come across is to fill a cell, not check if it has a fill. Heres my code so far:
coordinates = []
fl = PatternFill(patternType = "solid", fgColor="FFFFFF00", bgColor="FFFFFF00")
print (fl)
for d in ws['A']:
if str(d.value)[0:10] == str(last_day_of_month) and d.fill == fl:
coordinates.append(d.coordinate)
elif str(d.value)[0:10] == str(previous_month) and d.fill == fl:
coordinates.append(d.coordinate)
break
我不需要检查单元格的颜色是否正确,我只需要知道它是否突出显示,因此任何确定单元格是否填充的方法都会很棒.
I don't need to check if the cell is the correct color or not, I just need to know if its highlighted so any method to find out if the cell has a fill would be great.
答
试试这个:
if (d.font.color):
#it's highlighted
或者还有其他选择:
d.fill.start_color.index
希望这会有所帮助.