Unire file

Introduzione

Aspose.Cells for Python via .NET offre diversi modi per unire file. Per file semplici con dati, formattazione e formule, può essere usato il metodo Workbook.combine() per combinare vari workbook, e il metodo Worksheet.copy() per copiare i fogli di lavoro in un nuovo workbook. Questi metodi sono facili da usare ed efficaci, ma se hai molti file da unire, potresti scoprire che consumano molte risorse di sistema. Per evitare questo, usa il metodo statico CellsHelper.merge_files, un modo più efficiente per unire diversi file.

Unisci file usando Aspose.Cells for Python via .NET

Il seguente esempio di codice illustra come unire file di grandi dimensioni utilizzando il metodo CellsHelper.merge_files. Prende due file semplici ma di grandi dimensioni, Book1.xls e Book2.xls. I file contengono solo dati formattati e formule.

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")