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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
workbook = xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet('Sheet1')
style = xlwt.XFStyle() font = xlwt.Font() font.name = 'Times New Roman' font.height = 20 * 11 font.bold = True font.underline = True font.italic = True style.font = font
worksheet.write(0, 0, 'test_data') worksheet.write(1, 0, 'test_data', style)
worksheet.col(0).width = 3333
pattern = xlwt.Pattern() pattern.pattern = xlwt.Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 13 style = xlwt.XFStyle() style.pattern = pattern worksheet.write(2, 0, 'colour', style)
borders = xlwt.Borders() borders.left = xlwt.Borders.DASHED borders.right = xlwt.Borders.DASHED borders.top = xlwt.Borders.DASHED borders.bottom = xlwt.Borders.DASHED borders.left_colour=0x40 borders.right_colour = 0x40 borders.top_colour = 0x40 borders.bottom_colour = 0x40 style = xlwt.XFStyle() style.borders = borders worksheet.write(3,0 , 'border1', style)
borders = xlwt.Borders() borders.left = 1 borders.right = 1 borders.top = 1 borders.bottom = 1 borders.left_colour = 2 borders.right_colour = 2 borders.top_colour = 2 borders.bottom_colour = 2 style = xlwt.XFStyle() style.borders = borders worksheet.write(4, 0, 'border2', style)
worksheet.write(0, 1, 2) worksheet.write(0, 2, 3) worksheet.write(1, 1, xlwt.Formula('B1*C1')) worksheet.write(1, 2, xlwt.Formula('SUM(B1,C1)'))
worksheet.write(0, 3, xlwt.Formula('HYPERLINK("http://www.baidu.com";"baidu")'))
worksheet.write_merge(0, 0, 4, 5, 'First Merge') worksheet.write_merge(1, 2, 4, 5, 'Second Merge')
alignment=xlwt.Alignment() alignment.horz=xlwt.Alignment.HORZ_CENTER alignment.vert=xlwt.Alignment.VERT_CENTER style=xlwt.XFStyle() style.alignment=alignment worksheet.write(0, 6, 'alignment', style)
workbook.save('data_test.xls')
|