from openpyxl import load_workbookfrom openpyxl.styles import Font, Alignment, Side, Border, PatternFillfrom openpyxl.formatting.rule import ColorScaleRule, IconSetRule, DataBarRule, CellIsRule, FormulaRulewb = load_workbook("琼东西.xlsx")ws = wb["广西"]ws.conditional_formatting.add(range_string="A1:A10", cfRule=ColorScaleRule(start_type="min", start_color="00AA00", end_type="max", end_color="0000FF"))ws.conditional_formatting.add(range_string="B1:B10", cfRule=IconSetRule(icon_style="3Flags", type="num", values=[1, 5, 7], reverse=True))ws.conditional_formatting.add(range_string="C1:C10", cfRule=DataBarRule(start_type="num", start_value=None, end_type="num", end_value=10, showValue=True, color="FF0000"))redFill = PatternFill(end_color="00FFFF")ws.conditional_formatting.add(range_string="D1:D10", cfRule=CellIsRule(operator="lessThan", formula=[5], fill=redFill))redFill = PatternFill(end_color="FF00FF")ws.conditional_formatting.add(range_string="E1:E10", cfRule=FormulaRule(formula=["AND(E1>5, E1<=9)"], fill=redFill))wb.save("琼东西_条件格式.xlsx")