Openpyxl - 检查单元格是否已填充 [英] Openpyxl - checking if cell has fill

查看:77
本文介绍了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

希望这会有所帮助.

这篇关于Openpyxl - 检查单元格是否已填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆