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 文档

相关推荐
oyguyteggytrrwwwrt31 分钟前
3dgs渲染部分详细注释
python
天天爱吃肉82182 小时前
【重磅发布:拿下新超仁达代理权 】
大数据·人工智能·python·功能测试·汽车
神王宝宝 王者小学2 小时前
面向领域驱动架构的查询实现方式
前端·python·架构
ningmengjing_4 小时前
Redis 从入门到实战:Python操作全攻略
数据库·redis·python
️学习的小王4 小时前
智能文档助手:基于RAG的本地化文档问答系统实战指南
人工智能·python·机器学习
不瘦80斤不改名4 小时前
05-vibe-coding-向agentic-engineering演进
人工智能·笔记·python·prompt
笨鸟先飞,勤能补拙4 小时前
AI 安全的下一个 5 年:从 Agent 到 AGI 的攻防博弈
人工智能·python·安全·web安全·网络安全·github·agi
Logintern095 小时前
LangSmith如何根据id关系,在服务端把扁平列表重建为树形结构,用于页面渲染Trace视图
python
Arya_aa5 小时前
EasyExcel读和写
excel