将不同文件夹下名称相同的excel合并

怎样实现将不同文件夹下相同名称的excel文件合并到一个excel文件中

https://blog.csdn.net/weixin_47036600/article/details/129400596

可以用Spire.XLS for Python,下面代码里是文件名,你写成完整路径就行

from spire.xls import *
from spire.common import *

#Create a list of file paths for the Excel files to be merged
files = []
files.append("File-1.xlsx" )
files.append("File-2.xlsx")
files.append("File-3.xlsx")

#Create a new workbook
newbook = Workbook()
newbook.Version = ExcelVersion.Version2013
#Clear all default worksheets
newbook.Worksheets.Clear()

#Create a temporary workbook
tempbook = Workbook()

#Iterate through each file in the list of file paths
for file in files:
    #Load the file into the temporary workbook
    tempbook.LoadFromFile(file)
    #Iterate through each worksheet in the temporary workbook
    for sheet in tempbook.Worksheets:
        #Copy the worksheet from the temporary workbook to the new workbook
        newbook.Worksheets.AddCopy(sheet, WorksheetCopyType.CopyAll)

outputFile = "MergeExcelFiles.xlsx"        
#Save the merged file to a specific location
newbook.SaveToFile(outputFile, ExcelVersion.Version2013)
newbook.Dispose()
tempbook.Dispose()

具体可以参考这篇文章(要梯子)