openpyxl 设置单元格颜色
在处理excel数据格式的时候,需要对特定单元格进行颜色标注,方便相关人员查看 醒目
# -*- coding: utf-8 -*-
from openpyxl import load_workbook, Workbook
# 导入字体、边框、颜色以及对齐方式相关库
from openpyxl.styles import Font, Border, Side, PatternFill, colors, Alignment
有关颜色的设置具体可以查看 http://www.114la.com/other/rgb.htm
def MarkRedOverTime():
'''对上周已开船和未开船 超时数据字段进行标红'''
try:
abs_file = os.path.abspath(os.path.join(
os.path.dirname(__file__), outfile))
wb = load_workbook(abs_file)
# 获取工作表列表
sheets = wb.sheetnames
print(sheets)
# 获取某一特定的工作表
# 上一周新增的可发订单已开船数据 上一周新增的可发订单未开船数据
#
# 上一周新增的可发订单已开船数据ws = wb["上一周新增的可发订单未开船数据"] # # 设置填充红色加粗
red_fill = PatternFill("solid", fgColor="FF0000")
# # 遍历每一行
# for index, row in enumerate(ws.rows):
# if index > 0:
# # 单证工作时间(时) > 24
# cell6 = row[5]
# print(cell6.value)
# if int(cell6.value) > 24:
# cell6.fill = red_fill
# # 采购工作时间(时) > 48
# cell9 = row[8]
# if int(cell9.value) > 48:
# cell9.fill = red_fill
# # 订舱用时(时) > 48
# cell12 = row[11]
# if int(cell12.value) > 48:
# cell12.fill = red_fill
# # booking是否超时(天) < 0
# cell14 = row[13]
# if int(cell14.value) < 0:
# cell14.fill = red_fill
wt = wb["上一周新增的可发订单已开船数据"]
# 遍历每一行
for index, row in enumerate(wt.rows):
if index > 0:
# 单证工作时间(时) > 24
cell6 = row[5]
if int(cell6.value if cell6.value else "0") > 24:
cell6.fill = red_fill
# 采购工作时间(时) > 48
cell9 = row[8]
if int(cell9.value if cell9.value else "0") > 48:
cell9.fill = red_fill
# 订舱用时(时) > 48
cell12 = row[11]
if int(cell12.value if cell12.value else "0") > 48:
cell12.fill = red_fill
# booking是否超时(天) < 0
cell14 = row[13]
if int(cell14.value if cell14.value else "0") < 0:
cell14.fill = red_fill
# shipping是否超时(天) < 0
cell18 = row[17]
if int(cell18.value if cell18.value else "0") < 0:
cell18.fill = red_fill
wb.save(abs_file)
except Exception as error_msg:
print(error_msg)
fs = traceback.format_exc()
print(fs)
openpyxl 设置单元格颜色的更多相关文章
- unidbgrid 设置 单元格颜色
unidbgrid 设置 单元格颜色 2018年10月24日 11:32:41 ozhy111 阅读数:68 procedure TF_Resource2.UniDBGrid1DrawColumn ...
- 【手记】解决excel无法设置单元格颜色且界面怪异+桌面图标文字老有色块等问题
注:问题是在XP上遇到的,不知道是否适用其它系统 问题现象 excel 2010成这样了: 关键是设置不了单元格颜色,无论是文字颜色还是背景色都设置不了,设了没变化.同时会发现桌面图标的文字总有底色: ...
- Excel公式设置单元格颜色
Excel2010 “条件格式"-"新建规则"-"使用公式确定要设置格式的单元格" 公式如下: =OR(H2<=-20%,H2>=20%, ...
- ExtJS6 根据Value设置单元格颜色
renderer : function(value, meta) { if(parseInt(value) > 0) { meta.style = ""; } else { ...
- unigui 设置单元格颜色
procedure TF_Resource2.UniDBGrid1DrawColumnCell(Sender: TObject; ACol, ARow: Integer; Column: TUniD ...
- ABAP 设置单元格颜色
http://blog.163.com/ronanchen@126/blog/static/172254750201161811040488/ http://blog.csdn.net/lhx20/a ...
- ALV列、行、单元格颜色设置
)颜色含义 :海蓝:2:浅清:3:黄色:4:浅蓝:5:青色:6:红色:7:橙色. (1)首位为主颜色: (2)次位为辅助颜色: (3)末位为0时,表示首位数字表为表格的底色: 末位为1时,则表示以1为 ...
- VBA_Excel_教程:单元格颜色
Sub SetCellColor() '设置单元格颜色 Sheet1.Cells(, ).Interior.ColorIndex = End Sub
- NPOI 生成Excel (单元格合并、设置单元格样式:字段,颜色、设置单元格为下拉框并限制输入值、设置单元格只能输入数字等)
NPIO源码地址:https://github.com/tonyqus/npoi NPIO使用参考:源码中的 NPOITest项目 下面代码包括: 1.包含多个Sheet的Excel 2.单元格合并 ...
随机推荐
- curl 的用法指南
简介 curl 是常用的命令行工具,用来请求 Web 服务器.它的名字就是客户端(client)的 URL 工具的意思. 它的功能非常强大,命令行参数多达几十种.如果熟练的话,完全可以取代 Postm ...
- Hibernatne 缓存中二级缓存简单介绍
hibernate的session提供了一级缓存,每个session,对同一个id进行两次load,不会发送两条sql给数据库,但是session关闭的时候,一级缓存就失效了. 二级缓存是Sessio ...
- 这一次,真正掌握composer
思维导图 composer是现代PHP的基石 现代高级编程语言,依赖管理工具是必不可少的.Java有Maven,Python有pip,Nodejs有npm, 而在composer出现之前,PHP只 ...
- MVC模式实现注册登录
很多人对MVC模式搞不懂,刚开始是我也犯迷糊,知道看到一个前辈写的代码,我顿时有的恍然大悟,拿来分享给各位 MVC: 就是M:模型.V:视图(前台界面)C:后台处理的servlet 话不多说.上代码 ...
- lcd timing的理解
所谓调lcd timing就是去调lcd时序,一般是6个部分:HFPD(在一行扫描以前需要多少个像素时钟),HBPD(一行扫描结束到下一行扫描开始需要多少个像素时钟),VFPD(一帧开始之前需要多少个 ...
- Python: 对于DataFrame.loc传入列表和传入元组输出区别的理解
def test(): import pandas as pd tuples = [ ('cobra', 'mark i'), ('cobra', 'mark ii'), ('sidewinder', ...
- python线程信号量semaphore(33)
通过前面对 线程互斥锁lock / 线程事件event / 线程条件变量condition / 线程定时器timer 的讲解,相信你对线程threading模块已经有了一定的了解,同时执行多个线程的 ...
- 【leetcode算法-简单】38. 报数
[题目描述] 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 12. 113. 214. 12115. 1112211 被读作 "one 1&qu ...
- The Select mechanism in linux for block mechanism
Today, some one mention theknowledge of Select Mechanism. It's better to konw something about it ! O ...
- Python基础系列讲解——时间模块详解大全之time模块
Python中提供处理时间日期相关的内置模块有time.datetime和calendar. time模块中大多数函数调用了所在平台C library 的同名函数,因此更依赖于操作系统层面,所以tim ...