python xlwt设置单元格的自定义背景颜色 [英] python xlwt set custom background colour of a cell

查看:2439
本文介绍了python xlwt设置单元格的自定义背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python 2.7和xlwt模块进行excel导出



我想设置一个单元格的背景颜色
i知道我可以使用

  style1 = xlwt.easyxf('pattern:pattern solid,fore_colour red;')
/ pre>

但我想设置自定义颜色smth。像#8a8eef
或有可能的颜色调色板,因为浅蓝色不工作:)



谢谢

解决方案

如果你不使用 easyxf()而是建立 XFSt​​yle 对象一步一步,这里是使用用户友好颜色名称的另一种方法:

  import xlwt 

style = xlwt.XFStyle()
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = xlwt。 Style.colour_map ['dark_purple']
style.pattern = pattern


I am using python 2.7 and xlwt module for excel export

I would like to set backgroung colour of a cell i know i can use

style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')

but I would like to set custom color smth. like #8a8eef or is there a palette of possible colors, because light blue is not working :)

thank you

解决方案

If you are not using easyxf() and instead are building XFStyle object step by step, here is another way of using user friendly color names:

import xlwt

style = xlwt.XFStyle()
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = xlwt.Style.colour_map['dark_purple']
style.pattern = pattern

这篇关于python xlwt设置单元格的自定义背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆