在Python中,可以使用openpyxl库来操作Excel文件。要在一个长文件中添加多个唯一的Excel文件,可以按照以下步骤进行操作:
import openpyxl
wb = openpyxl.Workbook()
file_list = ['file1.xlsx', 'file2.xlsx', 'file3.xlsx'] # 需要添加的Excel文件列表
for file in file_list:
# 打开原始Excel文件
wb_source = openpyxl.load_workbook(file)
# 遍历原始Excel文件中的每个工作表
for sheet_name in wb_source.sheetnames:
# 创建新的工作表
ws_new = wb.create_sheet(title=sheet_name)
# 获取原始工作表
ws_source = wb_source[sheet_name]
# 复制原始工作表的数据到新的工作表
for row in ws_source.iter_rows(values_only=True):
ws_new.append(row)
# 关闭原始Excel文件
wb_source.close()
wb.save('output.xlsx')
这样,就可以将多个唯一的Excel文件添加到一个长文件中了。
推荐的腾讯云相关产品:腾讯云对象存储(COS)
请注意,以上答案仅供参考,具体实现方式可能因个人需求和环境而异。
领取专属 10元无门槛券
手把手带您无忧上云