使用create_sheet()方法新增工作表,title參數為工作表名稱
wb = load_workbook("Excel成績單.xlsx")
ws2=wb.create_sheet(title = "成績表2")
ws2["A1"] = "座號"
ws2["B1"] = "姓名"
ws2["C1"] = "國文"
ws2["D1"] = "數學"
ws.append([21, "Chang", 80, 95])
ws.append([22, "Chen", 90, 85])
wb.save("Excel成績單2.xlsx")
wb.close()
wb = load_workbook("Excel成績單.xlsx")
ws = wb.active
ws["E1"] = "總分"
ws["E2"] = "=SUM(C2:D2)"
ws["E3"] = "=SUM(C3:D3)"
wb.save("Excel成績單3.xlsx")
wb.close()
wb= load_workbook("Excel成績單.xlsx")
ws = wb["成績表1"]
ws.merge_cells("B2:C2")
ws.merge_cells("B3:C3")
wb.save("Excel成績單1.xlsx")
wb.close()