One, install xlwt
pip install xlwt
Two, write to excel
1. Code
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. Effect
Three, set the cell height and width
1. Code
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. Effect