在处理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. LINQ语法详解

    我会通过一些列的实例向大家讲解LINQ的语法. 先创建一个Person类,作为数据实体 public class Person { public string Name { get; set; } p ...

  2. python迭代器、生成器、装饰器之生成器

    python中只要函数内部包含有yield关键字,那么函数名()的到的结果就是生成器,并且不会执行函数内部代码,通过__next__()或者next()函数可以获取值,每调用一次,都会取出一个值,无值 ...

  3. iOS笔试题02

    1. Difference between shallow copy and deep copy? 1> 浅拷贝:指针(地址)拷贝,不会产生新对象 2> 深拷贝:内容拷贝,会产生新对象 2 ...

  4. eclipse 解决POM文件错误:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration)

    解决方案: 更新eclipse中的maven插件 1.1 Help -> Install New Software -> Add 1.2 Location中输入 http://repo1. ...

  5. 数据结构与算法学习(二)——Master公式及其应用

    本篇文章涉及公式,由于博客园没有很好的支持,建议移步我的CSDN博客和简书进行阅读. 1. Master公式是什么? 我们在解决算法问题时,经常会用到递归.递归在较难理解的同时,其算法的复杂度也不是很 ...

  6. web前端三大主流框架的对比

    MVX框架模式:MVC+MVP+MVVM 1.MVC:Model(模型)+View(视图)+controller(控制器),主要是基于分层的目的,让彼此的职责分开. View通过Controller来 ...

  7. JavaScript中的Truthy和Falsy

    JavaScript中存在Truthy值和Falsy值的概念 — 除了boolean值true.false外,所有类型的JavaScript值均可用于逻辑判断,其规则如下: 1.所有的Falsy值,当 ...

  8. 使用Cython时遇到的cl.exe的问题

    最近使用cython时,遇到一个问题,报错如下: cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-Id:\program files\python3 ...

  9. WIN10更换无线网卡后WIFI无法正常启用

    这里根据自己经历提供几个方案: 首先我们要确定这两个地方正常(表示网卡能识别.驱动安装好:有无线开关没打开的朋友请出门右转): 方案一:万能的重启,不觉得麻烦的就多重启几遍.大力出奇迹! 方案二:然后 ...

  10. spring cloud中代理服务器zuul的使用

    spring cloud中代理服务器zuul的使用 主流网关:     zuul     kong 基于nginx的API Gateway     nginx+lua 1.新建项目,选择eureka ...