# Coding: UTF. 8- Import Patterns Patterns AS Import xlwt Import Time I = 0 Book = xlwt.Workbook (encoding = ' UTF-. 8 ' ) Sheet = book.add_sheet ( ' Sheet1 ' , cell_overwrite_ok = True) # If an error occurs: Exception: Attempt to Overwrite cell: sheetname = 'Sheet1' rowx COLX = 0 = 0 # need to add: cell_overwrite_ok = True) # this is because repeating the operation of a cell resulting in the while I <64 : # Create font style font = xlwt.Font () #Font type font.name = ' name Times New Roman ' # font color font.colour_index = i # font size, font size 11, 20 denominations font.height = 20 * 11 # bold font . Font.Bold = False # underscore = font.underline True # italics Font.ITALIC = True # set cell alignment alignment = xlwt.Alignment () # 0x01 (left-justified), (center alignment in the horizontal direction) 0x02, 0x03 (right aligned) alignment.horz 0x02 = # 0x00 (upper alignment), 0x01 (center alignment vertically), 0x02 (align bottom) = 0x01 alignment.vert # Set wrap alignment.wrap = 1 # Set Border Borders = xlwt.Borders () # thin solid line: 1, small thick solid line: 2, a thin dashed line: 3, the thin dashed line: 4, large thick solid line: 5, double: 6, thin dotted line: 7 # large thick broken line: 8, fine-dot chain line: 9, the bold chain line: 10, thin double-dashed line: 11, thick double-dashed line: 12 oblique dotted chain line: 13 is 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 # Setting the column width, an English equivalent of two Chinese characters equal to two, the number of characters is 11, 256 denominations sheet.col (. 1) .width = 11 * 256 # set the background color pattern = xlwt.Pattern () # Set Background color mode pattern.pattern = xlwt.Pattern.SOLID_PATTERN # background color pattern.pattern_fore_colour = I # initialization pattern style0 = xlwt.XFStyle () style0.font = font style1 = xlwt.XFStyle () style1.pattern = pattern style2 = xlwt .XFStyle () style2.alignment = Alignment style3 = xlwt.XFStyle () style3.borders = Borders # Set Text font.num_format_str = ' #, ## 0.00 ' sheet.write (I, 0, U ' font ' , style0) sheet.write (I, . 1 , U ' background ' , style1) sheet.write (I, 2, U ' alignment ' , style2) sheet.write (I, . 3, U ' frame ' , style3) # merged cell line merging into the second section column 4 to column 54 line sheet.write_merge(2, 4, 4, 5, u'合并') i = i + 1 book.save('G:/test/xxx'+time.strftime("%Y%m%d%H%M%S")+'.xls')