一、安装xlwt
pip install xlwt
二、写入excel
1.代码
import xlwt
workbook = xlwt.Workbook(encoding='utf8')
worksheet = workbook.add_sheet('sheet1')
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = 'Times New Roman'
font.bold = True
font.underline = True
font.italic = True
style.font = font
worksheet.write(0, 0, '这是一个测试')
worksheet.write(1, 0, '这是一个测试', style)
workbook.save('C:\\Users\\Jonsson\\Desktop\\234.xls')
2.效果
三、设置单元格高度和宽度
1.代码
workbook = xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet('LOL')
worksheet.col(i).width = 4000
style = xlwt.easyxf('font:height 300')
worksheet.row(i).set_style(style)
workbook.save('C:\\Users\\Jonsson\\Desktop\\lol.xls')
2.效果