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

相关推荐
SilentSamsara3 分钟前
类型注解进阶:Union、Optional、Any 与 Callable
开发语言·python·青少年编程
爱喝热水的呀哈喽3 分钟前
gpt:RAG步骤
人工智能·python·机器学习
Fleshy数模7 分钟前
课堂教学质量评估系统:基于加权欧氏距离的评分实现
python·llm
恣艺7 分钟前
Python 游戏开发与文件处理:PyGame + Turtle + openpyxl + python-docx + PyPDF2
开发语言·python·pygame
_山海16 分钟前
用langchain 通过text-embedding-3-small生成embedding
python·langchain·llm
毋语天22 分钟前
FastAPI 网络编程入门到实战:从 HTTP 协议到异步 API 开发
python·网络编程·fastapi·rest api·异步编程
编程牛马姐27 分钟前
2026年Reddit养号指南:养号四个阶段实操
python·spring·intellij-idea
不懒不懒38 分钟前
Python+AI 大模型实现课堂教学质量智能分析|加权评分 + 自动诊断 + 改进建议
人工智能·python·深度学习·ai大模型·智慧教育·nlp算法
小新同学^O^1 小时前
OpenClaw 数据采集工具新手入门指南
python·学习·openclaw·纯ai文
爱喝水的木子1 小时前
提取html到markdown
人工智能·python