# Execle write module Import xlwt class WriteExecle (): DEF __init__ (Self, sheet_name, filename, header_data, the Data): '' ' : param sheet_name: Sheet Form Name : param filename: file storage execle absolute path : param header_data: Write the list header field data : param data: data is written '' ' self.sheet_name = SHEET_NAME self.filename = filename self.header_data = header_data self.data = data DEF write_execle (Self): Workbook = xlwt.Workbook ()#激活worksheet #worksheet = workbook.add_sheet(self.sheet_name) # 数据可以直接分配到单元格中 worksheet = workbook.add_sheet(self.sheet_name) for i in range(len(self.header_data)): ret = self.header_data[i][0] worksheet.write(0,i,ret) contenRow = len(self.data) first_col = [] for i in range(contenRow): first_col.append(self.data[i][0]) nfirst_col = list(set(first_col)) nfirst_col.sort(keyfirst_col.index =) # Sort Sort order is consistent with the original # Print ( "nfirst_col", nfirst_col) Row =. 1 for I in nfirst_col: COUNT = first_col.count (I) # repeats counting the number of elements, such as test:. 3 uprange row-COUNT +. 1 = # number scope of the uplink worksheet.write_merge (row, uprange, 0,0, I) # merged cell write to row = uprange. 1 + # next line written starting # acquired content child the second list element, and a circular write to the last two excel second start data for Row in Range (contenRow): for COL in Range (. 1, len (self.data [Row])): worksheet.write (Row + 1'd , COL, self.data [Row] [COL]) the try : workbook.save (self.filename) Print ( " the amount of data: { 0} is written. 1} { " .format (contenRow, self.filename)) the except : Print ( ' \ 033 [. 1; 35m failed: {} file is already open, close \ 033 [0m! ' .format ( self.filename))