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.单元格合并 ...
随机推荐
- tk mybatis动态sql中过滤不使用的字段
实体字段如下 @Data @NoArgsConstructor @AllArgsConstructor @Builder /*** * app图标 */ @JsonFormat public clas ...
- Tips for TMUX
常用命令 tmux ls # 显示后台session列表 tmux new -t [name] # 新建session tmux a -t [name] # 进入session tmux kill-s ...
- 【Leetcode_easy】788. Rotated Digits
problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...
- Linux - Linux命令行常用快捷键
Common Shortcut Key 用途 快捷键 说明 光标移动 Ctrl + a 把光标移到行首 Ctrl + e 把光标移到行尾 Ctrl + x 在 EOL 和当前位置移动光标 输入编辑 C ...
- c# 如何给 dataGridView里添加一个自增长列(列名为序号)
System.Data.DataTable table = new DataTable(); System.Data.DataColumn column = new Da ...
- [转]NopCommerce中的多商店支持:权威指南
[转]NopCommerce中的多商店支持:权威指南 多商店支持是最强大的nopCommerce功能之一.但究竟什么是多店支持?它是谁的?如何在nopCommerce中设置多个商店?在今天的帖子中,我 ...
- 【Aizu - 0189】Convenient Location (最短路 Floyd算法)
Convenient Location 直接翻译了 Descriptions 明年毕业的A为就业而搬家.就职的公司在若干城市都有办公室,不同天出勤的办公室也不同.所以A在考虑住在哪去各个办公室的时长最 ...
- pytest使用总结笔记
简介 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.并且pytest兼容unittest的用例,支 ...
- [转帖]Linux系列之SAR命令使用详解
Linux系列之SAR命令使用详解 sar是System Activity Reporter(系统活动情况报告)的缩写.这个工具所需要的负载很小,也是目前linux中最为全面的性能分析工具之一.此款工 ...
- 一文搞懂嵌入式uboot、kernel、文件系统的关系
总览: 在linux系统软件架构可以分为4个层次(从低到高分别为): 1.引导加载程序 引导加载程序(Bootloader)是固化在硬件Flash中的一段引导代码,用于完成硬件的一 ...