python-xlwt給excel添加樣式


#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")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM