1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import xlwt
titleStyle = xlwt.XFStyle()
titleFont = xlwt.Font() titleFont.name = "宋体" titleFont.bold = True titleFont.height = 11*20 titleFont.colour_index = 0x08 titleStyle.font = titleFont
cellAlign = xlwt.Alignment() cellAlign.horz = 0x02 cellAlign.vert = 0x01 titleStyle.alignment = cellAlign
wb = xlwt.Workbook()
ws = wb.add_sheet("Sheet1")
ws.write_merge(0,1,0,5,"大标题(单元格合并测试)",titleStyle)
data = (("小标题1","小标题2","小标题3"), ("值11","值12","值13"), ("值21","值22","值23") )
for row, item in enumerate(data): for col, val in enumerate(item): ws.write(row + 2, col, val)
wb.save("test.xls")
|