在处理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)

  

最新文章

  1. CGGeometry类定义几何元素的结构和操作几何元素的函数。
  2. 20145212《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDE)
  3. Python 利用pytesser模块识别图像文字
  4. [jQuery学习系列四 ]4-Jquery学习四-事件操作
  5. container宽度
  6. Category类别
  7. oracle误删的表恢复
  8. 【js编程艺术】小制作五
  9. OKMX6Q LTIB编译
  10. ACM Robot Motion
  11. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
  12. mysql执行update报错 Err] 1055 - &#39;information_schema.PROFILING.SEQ&#39; isn&#39;t in GROUP BY
  13. css干货部分
  14. [费用流][NOI2008]志愿者招募
  15. 解决springboot druid 数据库批量更新错误问题
  16. C++中函数的形参为数组时,实质形参是指针
  17. C++中几种测试程序运行时间的方法&lt;转&gt;
  18. Python 爬虫-正则表达式(补)
  19. 命令行下开启与关闭windows防火墙关端口(转)
  20. Jenkins HA高可用参考

热门文章

  1. redis列表和有序集合
  2. Asp.net C# 使用Newtonsoft.Json 实现DataTable转Json格式数据
  3. GraphQL学习之原理篇
  4. AWS 解决方案架构师考点(Storage)
  5. Python的发展历史及其前景
  6. Egret入门学习日记 --- 第三篇 (书中 3.4 内容)
  7. 关于React的脚手架
  8. 结合 Nginx 谈谈 Http 状态码
  9. Git 版本恢复命令reset
  10. glib系列1 编译