python 导出excel怎么设置样式_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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值