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

相关推荐
李昊哲小课7 分钟前
Python办公自动化教程 - 第5章 图表创建 - 让数据可视化
python·信息可视化·数据分析·数据可视化·openpyxl
chushiyunen14 分钟前
python pygame实现贪食蛇
开发语言·python·pygame
Dream of maid16 分钟前
Python-基础2(流程控制)
python
Lenyiin2 小时前
《Python 修炼全景指南:一》从环境搭建到第一个程序
开发语言·python
涛声依旧393162 小时前
Python项目实战:学生信息管理系统
开发语言·python·数据挖掘
kcuwu.2 小时前
Python进阶:生成器与协程,高效并发编程的核心实践
windows·python·php
XiaoQiao6669992 小时前
python 简单题目练手【详解版】【1】
开发语言·python
ZC跨境爬虫2 小时前
极验滑动验证码自动化实战:背景提取、缺口定位与Playwright滑动模拟
前端·爬虫·python·自动化
智算菩萨2 小时前
【Python图像处理】2 数字图像基础与Python图像表示
开发语言·图像处理·python
xiaoshuaishuai83 小时前
Git二分法定位Bug
开发语言·python