我的问题是条件格式设置规则,我想基于UP Aligned,DOWN Aligned或No Alignment的值将条件应用于电子表格中的列。诸如绿色表示“向上对齐”,蓝色表示“向下对齐”,红色表示“不对齐”。我想使用Openpyxl。我当前的代码是
from openpyxl.formatting import FormatRule
red_text = Font(color="9C0006")
red_fill = PatternFill(bgColor="FFC7CE")
dxf = DifferentialStyle(font=red_text, fill=red_fill)
rule = Rule(type="No Alignment", operator="No Alignment",
text="highlight", dxf=dxf)
rule.formula = ['NOT(ISERROR(SEARCH("highlight",A1)))']
ws.conditional_formatting.add('A1:F40', FormatRule(text=['No Alignment'],
stopIfTrue=True, fill=redFill))
#wb.save("test.xlsx")