Openpyxl:CellIsRule 函数意外失败

Openpyxl: unexpected fail with CellIsRule function

我正在打开一个 Excel 文件并应用一些条件格式:

from openpyxl import *
from openpyxl.formatting.rule import CellIsRule

os.chdir(r'C:\Users\myfolder')

wb= load_workbook('myfile.xlsx')
ws = wb.active

#Conditional formatting
ws.conditional_formatting.add('S3:S89', formatting.CellIsRule(operator='equal', formula=['1'], font='#FF0000')) #Red

这是基于完成的。但是,我收到此错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-190-fb94e6065444> in <module>()
---> 10 ws.conditional_formatting.add('S3:S89', formatting.CellIsRule(operator='equal', formula=['1'], font='#FF0000')) #Red

AttributeError: module 'openpyxl.formatting' has no attribute 'CellIsRule'

这是怎么回事?我使用的是 openpyxl 2.4.8 版,而这个答案是为 2.2.6 版提供的。但是,CellIsRule 函数似乎仍然存在。我错过了什么?

尝试以下类型的方法:

import openpyxl

os.chdir(r'C:\Users\myfolder')

wb = openpyxl.load_workbook('myfile.xlsx')
ws = wb.active

#Conditional formatting
red_font = openpyxl.styles.Font(size=14, bold=True, color='9c0103')
ws.conditional_formatting.add('S3:S89', openpyxl.formatting.rule.CellIsRule(operator='equal', formula=['1'], font=red_font)) #Red