在处理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 设置单元格颜色的更多相关文章

  1. unidbgrid 设置 单元格颜色

    unidbgrid 设置 单元格颜色 2018年10月24日 11:32:41 ozhy111 阅读数:68   procedure TF_Resource2.UniDBGrid1DrawColumn ...

  2. 【手记】解决excel无法设置单元格颜色且界面怪异+桌面图标文字老有色块等问题

    注:问题是在XP上遇到的,不知道是否适用其它系统 问题现象 excel 2010成这样了: 关键是设置不了单元格颜色,无论是文字颜色还是背景色都设置不了,设了没变化.同时会发现桌面图标的文字总有底色: ...

  3. Excel公式设置单元格颜色

    Excel2010 “条件格式"-"新建规则"-"使用公式确定要设置格式的单元格" 公式如下: =OR(H2<=-20%,H2>=20%, ...

  4. ExtJS6 根据Value设置单元格颜色

    renderer : function(value, meta) { if(parseInt(value) > 0) { meta.style = ""; } else { ...

  5. unigui 设置单元格颜色

    procedure TF_Resource2.UniDBGrid1DrawColumnCell(Sender: TObject; ACol,  ARow: Integer; Column: TUniD ...

  6. ABAP 设置单元格颜色

    http://blog.163.com/ronanchen@126/blog/static/172254750201161811040488/ http://blog.csdn.net/lhx20/a ...

  7. ALV列、行、单元格颜色设置

    )颜色含义 :海蓝:2:浅清:3:黄色:4:浅蓝:5:青色:6:红色:7:橙色. (1)首位为主颜色: (2)次位为辅助颜色: (3)末位为0时,表示首位数字表为表格的底色: 末位为1时,则表示以1为 ...

  8. VBA_Excel_教程:单元格颜色

    Sub SetCellColor() '设置单元格颜色 Sheet1.Cells(, ).Interior.ColorIndex = End Sub

  9. NPOI 生成Excel (单元格合并、设置单元格样式:字段,颜色、设置单元格为下拉框并限制输入值、设置单元格只能输入数字等)

    NPIO源码地址:https://github.com/tonyqus/npoi NPIO使用参考:源码中的 NPOITest项目 下面代码包括: 1.包含多个Sheet的Excel 2.单元格合并 ...

随机推荐

  1. windows 2008+IIS7+Mysql+PHP5.5 + FastCGI环境配置

    一.软件下载 操作系统:Windows Server 2008 R2 Enterprise (1)IIS:windows server2008系统是自带的,但要用户自己全新安装,具体方法见教程下方 ( ...

  2. zabbix3.4配置windowsAD登录

    转载自:[https://zabbix.com/documentation/3.4/zh/manual/web_interface/frontend_sections/administration/a ...

  3. Jenkins备份插件backup

    这个插件可以备份Jenkins的JENKINS_HOME目录,并恢复,但是版本太旧了. 有一些其他插件可以定时备份,搜索Backup https://www.cnblogs.com/cxwblog/p ...

  4. pipeline代码自动生成

    如图所示,安装完插件后,Sample Step里就有相应的选项,选择某个选项后,点击Generate Pipeline Script按钮,就可以自动生成代码片段,然后放入pipeline流水线里就可以 ...

  5. 关于PADS的一些概念和实用技巧(二)

    关于PADS的一些概念和实用技巧(二) 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 1. 关于制作part 首先在logic中绘制CAE封装,在保存元件时 ...

  6. thinkphp5 引用 phpass加密算法

    引入phpass thinkPHP5 放到扩展目录里 自动加载配置 直接实例化 // 初始化散列器为不可移植(这样更安全) $PasswordHashs = new \PasswordHashs(8, ...

  7. Spring 使用日期类型

    1. 数据层数据类型依赖包  java.time.LocalDate 2.pom.xml添加依赖 <dependency> <groupId>org.thymeleaf.ext ...

  8. ROS学习(二)运行keyboard

    1.ssh连接机器人 ./dora*.sh 启动roscore,相当于启动ros系统 roscore 2.另启终端,也就意味着重新ssh连接机器人, ./dora*.sh 运行wheel驱动 rosr ...

  9. vue+element-ui 实现table单元格点击编辑,并且按上下左右键单元格之间切换

    通过我的测试我发现两个两种方法来编辑单元格的内容 第一种点击编辑: 我是给td里添加一个input,将值赋值给input,当失去焦点的时候将input的值付给td原来的内容,然后将input删除, 代 ...

  10. Python列表排序方法reverse、sort、sorted详解

    python语言中的列表排序方法有三个:reverse反转/倒序排序.sort正序排序.sorted可以获取排序后的列表.在更高级列表排序中,后两中方法还可以加入条件参数进行排序. reverse() ...