Merge Files

Introduction

Aspose.Cells for Python via .NET provides different ways for merging files. For simple files with data, formatting, and formulas, the Workbook.combine() method can be used to combine several workbooks, and the Worksheet.copy() method can be used to copy worksheets into a new workbook. These methods are easy to use and effective, but if you have a lot of files to merge, you might find that they take a lot of system resources. To avoid this, use the CellsHelper.merge_files static method, a more efficient way to merge several files.

Merge Files Using Aspose.Cells for Python via .NET

The following sample code illustrates how to merge large files using the CellsHelper.merge_files method. It takes two simple but large files, Book1.xls and Book2.xls. The files contain formatted data and formulas only.

from aspose.cells import Workbook, CellsHelper
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Create an Array (length=2)
files = ["Book1.xls", "Book1.xlsx"]
# Create a cachedFile for the process
cacheFile = "test.txt"
# Output File to be created
dest = "output.xlsx";
# # Merge the files in the output file. Supports only .xls files
CellsHelper.merge_files(files, cacheFile, dest);
# Now if you need to rename your sheets, you may load the output file
workbook = Workbook("output.xlsx")
i = 1
# Browse all the sheets to rename them accordingly
for sheet in workbook.worksheets:
sheet.name = "Sheet1" + str(i)
i
i = i + 1
# Re-save the file
workbook.save("output.xlsx")