#coding:utf-8
import os
import time
import xlwt
filename="test_xlwt.xls"
if os.path.exists(filename):
os.remove(filename)
def set_color(color,bold):
style=xlwt.XFStyle()
font=xlwt.Font()
font.colour_index=color
font.bold = bold
style.font=font
return style
title_style=set_color(0x06,True)
xls=xlwt.Workbook()
shet1=xls.add_sheet("test_sheet")
shet1.write(0,0,"test",set_color(0x02,True)) #红色
shet1.write(0,1,"test",set_color(0x05,False)) #黄色
shet1.write(0,2,u"你好",set_color(0x00,True)) #黑色加粗
shet1.write(0,3,u"你好",set_color(0x00,False)) #黑色不加粗
shet1.write(0,4,u"你好",title_style) #黑色加粗
xls.save("test_xlwt.xls")
转载于:https://www.cnblogs.com/hanjiajiejie/p/9370253.html