2016-12-21 85 views
0

我试图检查单元格是否以黄色突出显示。我遇到的所有帖子都是为了填满一个单元格,而不是检查它是否有填充。继承人我到目前为止的代码:Openpyxl - 检查单元格是否已填充

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 

我并不需要检查,如果该细胞是正确的颜色与否,我只需要知道它强调了这样的任何方法,以找出是否细胞具有填充会很好。

回答

0

试试这个:

if (d.font.color): 
    #it's highlighted 

或者还有另一种选择:

d.fill.start_color.index 

希望这有助于。

+0

它返回'无'。我真的很希望这很容易。 –

+0

@DavidVo你确定你有指示正确的行,列等? – Nurjan

+0

@DavidVo我编辑了答案。试试看。 – Nurjan