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
| import openpyxl
workbook = openpyxl.load_workbook("test.xlsx")
sheetnames = workbook.sheetnames
worksheet = workbook["总表"]
CountRows = worksheet.max_row CountColumns = worksheet.max_column
worksheetnamelist = []
AllTitleList = [] for cell in worksheet.columns: AllTitleList.append(cell[0].value)
NumList = [] NameList = [] for i in range(2, 31): NumList.append(worksheet.cell(row=i, column=1).value) NameList.append(worksheet.cell(row=i, column=2).value)
count = 0 for start_column in range(3, CountColumns + 1, 14): count += 1 current_worksheet = workbook.create_sheet() current_worksheet.title = worksheet.cell(row=1, column=start_column).value + "-" + worksheet.cell(row=1,column=start_column + 13).value current_worksheet.cell(1, 1, "学号") current_worksheet.cell(1, 2, "姓名") for i in range(2, 31): current_worksheet.cell(i, 1, NumList[i - 2]) current_worksheet.cell(i, 2, NameList[i - 2]) for i in range(start_column, start_column + 14): print(AllTitleList[i - 1]) current_worksheet.cell(1, i - (count - 1) * 14, AllTitleList[i - 1]) for j in range(2, 31): current_worksheet.cell(j, i - (count - 1) * 14, worksheet.cell(row=j, column=i).value)
print("----") workbook.save(filename="test.xlsx")
|