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

相关推荐
曲幽3 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
warm3snow7 小时前
AI 重塑产品管理工具:从 Jira 到智能体项目经理的终极演进
人工智能·ai·excel·项目管理·飞书·产品经理·jira·协同·tapd
用户8356290780518 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon9 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly9 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程9 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly11 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风18 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风18 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法