import os import pandas as pd # 合并两个excel到一个excel的不同sheet def merge_excel(p_path, s_path, m_path): writer = pd.ExcelWriter(m_path) if os.path.isfile(p_path): data1 = pd.read_excel(p_path, dtype='str') data1.to_excel(writer, index=False, header=True, sheet_name='YECEJ533过账结果') if os.path.isfile(s_path): data2 = pd.read_excel(s_path, dtype='str') data2.to_excel(writer, index=False, header=True, sheet_name='YXFI213_2查询结果') writer.save() writer.close() merge_excel(post_file_path, search_file_path, merge_file_path) result = '合并excel成功'