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

相关推荐
Wise玩转AI2 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
s***46982 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
runepic3 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
codists3 小时前
2025年11月文章一览
python
生而为虫3 小时前
31.Python语言进阶
python·scrapy·django·flask·fastapi·pygame·tornado
言之。3 小时前
Claude Code 实用开发手册
python
计算机毕设小月哥3 小时前
【Hadoop+Spark+python毕设】中国租房信息可视化分析系统、计算机毕业设计、包括数据爬取、Spark、数据分析、数据可视化、Hadoop
后端·python·mysql
2***c4353 小时前
Redis——使用 python 操作 redis 之从 hmse 迁移到 hset
数据库·redis·python
二川bro5 小时前
模型部署实战:Python结合ONNX与TensorRT
开发语言·python
秋邱5 小时前
AI + 社区服务:智慧老年康养助手(轻量化落地方案)
人工智能·python·重构·ar·推荐算法·agi