pands使用openpyxl引擎实现EXCEL条件格式

通过python的openpyxl库,实现公式条件格式。

实现内容:D列单元格不等于E列同行单元格时标红。

#重点是formula=后面的公式不需要"="号。

python 复制代码
from openpyxl.styles import Color, PatternFill, Font, Border
from openpyxl.styles.differential import DifferentialStyle
from openpyxl.formatting.rule import ColorScaleRule, CellIsRule, FormulaRule, Rule

    redFill = PatternFill(start_color='EE1111',
               end_color='EE1111',
               fill_type='solid')
#重点是formula=后面的公式不需要"="号。
    ws.conditional_formatting.add('D3:E7',FormulaRule(formula=['$D3<>$E3'],stopIfTrue=True,fill=redFill))

官方文档参考:条件格式 --- openpyxl 3.0.5 文档

相关推荐
梁正雄37 分钟前
Python前端-2-css基础
前端·python·html
MoRanzhi12031 小时前
Pillow 图像颜色模式与颜色空间转换
图像处理·python·数学建模·pillow·颜色空间转换·颜色模式·图像通道
&Darker1 小时前
十三、大语言模型微调
人工智能·python·语言模型
小白学大数据1 小时前
对比分析:Python爬虫模拟登录的3种主流实现方式
开发语言·爬虫·python·数据分析
与虾牵手1 小时前
用 Python 从零搭一个能用的 AI Agent,踩完坑我总结了这套模板
python·aigc·ai编程
AsDuang2 小时前
Python 3.12 MagicMethods - 38 - __ifloordiv__
开发语言·python
深蓝电商API2 小时前
旅游网站景点评论情感分析
爬虫·python
运维老王2 小时前
运维人如何用 Python 自动化提升 10 倍效率
python
AI-小柒2 小时前
OpenClaw技术深度解析:从智能助手到自动化引擎的范式革命(附DataEyes实战)
大数据·运维·开发语言·人工智能·python·http·自动化