aqua | dark_green | gray40 | light_orange | periwinkle | teal |
black | dark_green_ega | gray50 | light_turquoise | pink | teal_ega |
blue | dark_purple | gray80 | light_yellow | plum | turquoise |
blue_gray | dark_red | green | lime | purple_ega | violet |
bright_green | dark_red_ega | ice_blue | magenta_ega | red | white |
brown | dark_teal | indigo | ocean_blue | rose | yellow |
coral | dark_yellow | ivory | olive_ega | sea_green | |
cyan_ega | gold | lavender | olive_green | silver_ega | |
dark_blue | gray_ega | light_blue | orange | sky_blue | |
dark_blue_ega | gray25 | light_green | pale_blue | tan |
easyxf 能理解以上颜色种类,写了脚本生成对应的颜色进行预览, xlwt_colour 的第一列填写以上颜色种类,脚本运行完后第二列生成对应颜色
#!/usr/bin/env python
# coding=utf-8
from xlrd import open_workbook
from xlwt import easyxf, XFStyle, Pattern
from xlutils.copy import copy
def set_style(colour):
return easyxf(
'pattern: pattern solid, fore_colour %s;' % colour
)
rbook = open_workbook('xlwt_colour.xls')
rsheet = rbook.sheet_by_index(0)
wbook = copy(rbook)
wsheet = wbook.get_sheet(0)
rows = rsheet.nrows
for r in range(rows):
coltxt = str(rsheet.cell(r, 0).value)
wsheet.write(r, 1, None, set_style(coltxt))
wsheet.col(0).width = 6000
wsheet.col(1).width = 3000
wbook.save('xlwt_colour.xls')