问题
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.
回答1:
Try this:
if (d.font.color):
#it's highlighted
Or there is another option:
d.fill.start_color.index
Hope this helps.
来源:https://stackoverflow.com/questions/41256943/openpyxl-checking-if-cell-has-fill