دمج الملفات
مقدمة
يوفر Aspose.Cells for Python via .NET طرقًا مختلفة لدمج الملفات. للملفات البسيطة التي تحتوي على بيانات وتنسيقات وصيغ، يمكن استخدام طريقة Workbook.combine() لدمج عدة ملفات عمل، ويمكن استخدام طريقة Worksheet.copy() لنسخ أوراق العمل إلى ملف عمل جديد. هذه الطرق سهلة الاستخدام وفعالة، ولكن إذا كان لديك العديد من الملفات لدمجها، فقد تكتشف أنها تستهلك الكثير من موارد النظام. لتجنب ذلك، استخدم الطريقة الثابتة CellsHelper.merge_files، وهي وسيلة أكثر كفاءة لدمج عدة ملفات.
دمج الملفات باستخدام Aspose.Cells for Python via .NET
يوضح الكود العيني التالي كيفية دمج الملفات الكبيرة باستخدام الطريقة CellsHelper.merge_files. يأخذ ملفين بسيطين ولكن كبيرين فقط، Book1.xls و Book2.xls. يتضمن الملفات بيانات مهيأة وصيغ فقط.
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") |