import os
import pandas as pd
# 设定目录和sheet的名称
directory = 'path_to_your_directory'
sheet_name = 'your_sheet_name'
output_file = 'merged_sheets.xlsx'
# 初始化一个空的DataFrame,用于之后合并数据
all_data = pd.DataFrame()
# 遍历目录下的所有文件
for file in os.listdir(directory):
if file.endswith('.xlsx') and not file.startswith('~$'): # 跳过临时文件
file_path = os.path.join(directory, file)
# 读取每个文件的指定sheet
df = pd.read_excel(file_path, sheet_name=sheet_name)
# 将数据添加到all_data DataFrame
all_data = all_data.append(df, ignore_index=True)
# 将合并后的数据写入新的Excel文件
all_data.to_excel(output_file, index=False)
chatgpt
--
FROM 111.206.214.*