当缺少值时,Python Openpyxl会更改单元格颜色

时间:2018-02-02 03:05:26

标签: python excel openpyxl

我有一个看起来像这样的excel表

tmp(1) = 1203
tmp(2) = 59

tmp(1) = 1203
tmp(2) = 59
tmp(3) = 44

tmp(1) = 1203
tmp(3) = 44

如果缺少这样的数据,它会从16:00:00跳到19:00:00,

2013-01-23 08:00:00 +0000 UTC
2013-01-23 09:00:00 +0000 UTC
2013-01-23 10:00:00 +0000 UTC
2013-01-23 11:00:00 +0000 UTC
2013-01-23 12:00:00 +0000 UTC
2013-01-23 13:00:00 +0000 UTC
2013-01-23 15:00:00 +0000 UTC
2013-01-23 16:00:00 +0000 UTC
2013-01-23 19:00:00 +0000 UTC
2013-01-23 20:00:00 +0000 UTC

我想将字体颜色更改为红色

是否可以使用python openpyxl包来实现?

1 个答案:

答案 0 :(得分:1)

是的,您可以使用openpyxl将字体颜色更改为红色。的 More Info

示例: (来自文档)

>>> from openpyxl.styles import colors
>>> from openpyxl.styles import Font, Color
>>> from openpyxl import Workbook
>>> wb = Workbook()
>>> ws = wb.active
>>>
>>> a1 = ws['A1']
>>> d4 = ws['D4']
>>> ft = Font(color=colors.RED)
>>> a1.font = ft
>>> d4.font = ft