Python Excel 条件格式化中如何根据数值的正负使用 iconset

![img](在Excel表格中:
(1)如果一列中某格的数值大于零,显示向上的箭头
(2)如果一列中某格的数值小于零,显示向下的箭头
(3)如果一列中某格的数值等于零,显示向右的箭头


from openpyxl import load_workbook
from openpyxl.formatting.rule import IconSetRule

workbook = load_workbook(filename="sample.xlsx")
sheet = workbook.active

icon_set_rule = IconSetRule("3Arrows", "num", [-1, 0, 1])
sheet.conditional_formatting.add("A2:A25", icon_set_rule)
workbook.save("sample.xlsx")

Excel自动把该列(A列)全部数值计算67%位置和33%位置的值,据此分配箭头,因此我上面的编程不能达到我的目的。

我用[-1, 0, 1]也是处于无奈,因为 openpyxl 不能用 IconSetRule("3Arrows", "num", [>0, =0, <0])

非常感谢!

https://img-mid.csdnimg.cn/release/static/image/mid/ask/782937178826111.png 'iconset.png')

# setup rules
first = FormatObject(type='num', val=-50)
second = FormatObject(type='num', val=0)
third = FormatObject(type='num', val=1)
iconset = IconSet(iconSet='3Arrows', cfvo=[first, second, third], showValue=None, percent=None, reverse=None)
# assign the icon set to a rule
rule = Rule(type='iconSet', iconSet=iconset)