import patterns as patterns
import xlwt
import time
i = 0
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
while i < 64:
font = xlwt.Font()
font.name = 'name Times New Roman'
font.colour_index = i
font.height = 20*11
font.bold = False
font.underline = True
font.italic = True
alignment = xlwt.Alignment()
alignment.horz = 0x02
alignment.vert = 0x01
alignment.wrap = 1
borders = xlwt.Borders()
borders.left = 1
borders.right = 2
borders.top = 3
borders.bottom = 4
borders.left_colour = i
borders.right_colour = i
borders.top_colour = i
borders.bottom_colour = i
sheet.col(1).width = 11 * 256
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = i
style0 = xlwt.XFStyle()
style0.font = font
style1 = xlwt.XFStyle()
style1.pattern = pattern
style2 = xlwt.XFStyle()
style2.alignment = alignment
style3 = xlwt.XFStyle()
style3.borders = borders
font.num_format_str = '#,##0.00'
sheet.write(i, 0, u'字体', style0)
sheet.write(i, 1, u'背景', style1)
sheet.write(i, 2, u'对齐方式', style2)
sheet.write(i, 3, u'边框', style3)
sheet.write_merge(2, 4, 4, 5, u'合并')
i = i + 1
book.save('E:/test/testfile/test_file'+time.strftime("%Y%m%d%H%M%S")+'.xls')