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

相关推荐
qq_460978404 分钟前
实现 Svelte 中基于数组索引的 details 元素单开单关交互
jvm·数据库·python
AI科技星15 分钟前
ELN 升级:π 级数自动生成器全域数理架构
大数据·人工智能·python·算法·金融
用户93520139867929 分钟前
淘宝开放平台 item_cat_get 接口详解:获取淘宝商品类目
python
dfdfadffa35 分钟前
SQL窗口函数如何优化嵌套子查询_提升执行效率
jvm·数据库·python
时空系42 分钟前
第6篇:多维数据盒——管理大量数据 python中文编程
开发语言·python·ai编程
小敬爱吃饭1 小时前
知识图谱实战第一章:知识图谱全景解析其定义、技术演进与十大应用场景
人工智能·python·目标检测·自然语言处理·flask·nlp·知识图谱
m0_588758481 小时前
如何查看集群版本_crsctl query crs activeversion当前版本
jvm·数据库·python
陳錄生1 小时前
Emacs 读sql server数据库(数据cp936)中文乱码问题。
python·emacs·sql server
TestCopilot1 小时前
从零用 Python 实现最基础的MCP协议
python·mcp