The source code is as follows:
#!/usr/bin/python#coding=utf-8import xlrdfrom prettytable Import prettytabledef sheetrowtoslice (sheet, R, Colnum): res = [] for C in range (colnum): Cell_value = Sheet.cell (R, c). Value if Isinstance (CE Ll_value, str): Cell_value = ' \ n '. Join (Cell_value.split (")) Res.append (Sheet.cell ( R, c). Value) return Resdef appendslicetotable (table, res): Table.append (res) returndata = Xlrd.open_w Orkbook ("test.xlsx") sheet = data.sheets () [0]nrows_num = Sheet.nrowsncols_num = sheet.ncolsfor r in range (Nrows_num): Cell_value = str (Sheet.cell (r, 0). Value.encode ("UTF8")) if "Name" in Cell_value:common_row_num = R if "Total" in cell_value:end_row_num = Rcommon_row = Sheetrowtoslice (sheet, common_row_num, Ncols_nu m) Table = prettytable (Common_row) table.add_row (Sheetrowtoslice (sheet, Common_row_num + 1, ncols_num)) print table.get_ String ()
Python reads Excel and tabulation output