xlwt.easyxf() 設定樣式,pattern 指的就是背景,ice_blue 就是我設定的顔色。
font 就是設定字型,bold on 是加粗。
樣式可以合一起,之間用分号
;
分開。 # 設定顔色
style = xlwt.easyxf('pattern: pattern solid, fore_colour ice_blue')
# 字型加粗
style = xlwt.easyxf('font: bold on')
#樣式合并
style = xlwt.easyxf('pattern: pattern solid, fore_colour ice_blue; font: bold on')
# 為指定單元格設定樣式
sheets.write(0, 0, "hello girl", style)
運作效果圖:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5iMjhzYiZDM0cDZxMTY5MmYiVjZ0UGO5EGZhFmZ1MTY58CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
顔色表:
aqua 0x31
black 0x08
blue 0x0C
blue_gray 0x36
bright_green 0x0B
brown 0x3C
coral 0x1D
cyan_ega 0x0F
dark_blue 0x12
dark_blue_ega 0x12
dark_green 0x3A
dark_green_ega 0x11
dark_purple 0x1C
dark_red 0x10
dark_red_ega 0x10
dark_teal 0x38
dark_yellow 0x13
gold 0x33
gray_ega 0x17
gray25 0x16
gray40 0x37
gray50 0x17
gray80 0x3F
green 0x11
ice_blue 0x1F
indigo 0x3E
ivory 0x1A
lavender 0x2E
light_blue 0x30
light_green 0x2A
light_orange 0x34
light_turquoise 0x29
light_yellow 0x2B
lime 0x32
magenta_ega 0x0E
ocean_blue 0x1E
olive_ega 0x13
olive_green 0x3B
orange 0x35
pale_blue 0x2C
periwinkle 0x18
pink 0x0E
plum 0x3D
purple_ega 0x14
red 0x0A
rose 0x2D
sea_green 0x39
silver_ega 0x16
sky_blue 0x28
tan 0x2F
teal 0x15
teal_ega 0x15
turquoise 0x0F
violet 0x14
white 0x09
yellow 0x0D
喜歡的點個贊❤吧!