import pandas as pd import tkinter as tk from tkinter import filedialog, Button # 添加 Button 到导入列表中 def merge_and_save(): # 打开文件选择对话框,选择Excel文件 file_path = filedialog.askopenfilename(title="选择Excel文件", filetypes=[("Excel文件", "*.xlsx")]) # 读取Excel文件中的所有工作表 all_sheets = pd.read_excel(file_path, sheet_name=None) # 合并所有工作表的数据到一个新表中 merged_data = pd.concat(all_sheets, ignore_index=True) # 将合并后的数据保存到新的Excel文件中 output_file = filedialog.asksaveasfilename(defaultextension=".xlsx", filetypes=[("Excel文件", "*.xlsx")]) merged_data.to_excel(output_file, index=False) print(f"数据已合并并保存到 {output_file}") # 创建GUI窗口 root = tk.Tk() root.title("Excel数据合并工具(文件中多个sheets合并到一起)") # 设置标题 root.configure(background='darkblue') # 设置背景颜色为蓝色 root.geometry("600x300") # 设置窗口大小为6000x300像素 # 添加文字说明 label = tk.Label(root, text="1.选择你文件夹中要合并的文件\n2.跟着会弹出要保存的路径界面\n3.自定义名称并保存到你指定地方\n4.程序会自动处理", bg="darkblue", fg="white", font=("Arial", 16)) label.pack(pady=10) # 垂直方向上添加一些间距 # 在标签的右下角添加作者信息 author_label = tk.Label(root, text="作者:sy", bg="darkblue", fg="white", font=("Arial", 12)) author_label.place(x=350, y=270, anchor="se") # 将作者标签放置在标签的右下角 # 创建文件选择按钮 file_select_button = Button(root, text="选择文件", command=merge_and_save) file_select_button.pack() # 创建关闭按钮 close_button = Button(root, text="关闭", command=root.quit) close_button.pack() root.mainloop() # 启动GUI事件循环