本代碼兼顧了合併sheet與合併表格的功能app
import os import pandas as pd
def combine_sheet(excel_path, number): #excel_path is str and num is the sequence number of the excel excel = pd.read_excel(excel_path, sheet_name = None, header = None) keys = list(excel.keys()) excel_contact = pd.DataFrame() for i in keys: excel_sheet = excel[i] excel_contact = pd.concat([excel_contact, excel_sheet]) excel_contact.to_excel('vocabulary{}.xlsx'.format(number), header= False, index=None) def combine_excel(excels_path): #excel_path is a list of excel files' name excel_combination = [] for i in excels_path: excel_combination.append(pd.read_excel(i, header=None)) new_excel = pd.concat(excel_combination) new_excel.to_excel('vocabulary.xlsx', header = False, index=None) os.chdir('C:\\Users\\11440\\OneDrive') combine_sheet('詞彙.xlsx', 1) combine_sheet('詞彙2.xlsx', 2) excel_list = ["vocabulary1.xlsx", "vocabulary2.xlsx"] combine_excel(excel_list)