Dosyaları Birleştirme
Giriş
Aspose.Cells, dosyaları birleştirmek için farklı yöntemler sunar. Basit dosyalar için, Workbook.combine() yöntemi birkaç çalışma kitabını birleştirmek için kullanılabilir ve Worksheet.copy() yöntemi çalışsayıları yeni bir çalışma kitabına kopyalamak için kullanılabilir. Bu yöntemler kullanımı kolaydır ve etkilidir, ancak birçok dosyayı birleştirmeniz gerekiyorsa, sistem kaynaklarını çok fazla kullandıklarını görebilirsiniz. Bunu önlemek için, daha verimli birleştirmek için CellsHelper.mergeFiles statik yöntemini kullanın.
Aspose.Cells Kullanarak Dosyaları Birleştirme
Aşağıdaki örnek kod, CellsHelper.mergeFiles yöntemini kullanarak büyük dosyaları nasıl birleştirileceğini gösterir. MyBook1.xls ve MyBook2.xls adlı iki basit ama büyük dosyayı içerir. Dosyalar yalnızca biçimlendirilmiş veri ve formülleri içerir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getSharedDataDir(MergeFiles.class) + "CellsHelperClass/"; | |
// Create an Array (length=2) | |
String[] files = new String[2]; | |
// Specify files with their paths to be merged | |
files[0] = dataDir + "Book1.xls"; | |
files[1] = dataDir + "Book2.xls"; | |
// Create a cachedFile for the process | |
String cacheFile = dataDir + "test.txt"; | |
// Output File to be created | |
String dest = dataDir + "MergeFiles_out.xls"; | |
// Merge the files in the output file | |
CellsHelper.mergeFiles(files, cacheFile, dest); | |
// Now if you need to rename your sheets, you may load the output file | |
Workbook workbook = new Workbook(dataDir + "MergeFiles_out.xls"); | |
int cnt = 1; | |
// Browse all the sheets to rename them accordingly | |
for (int i = 0; i < workbook.getWorksheets().getCount(); i++) { | |
workbook.getWorksheets().get(i).setName("Sheet1" + cnt); | |
cnt++; | |
} | |
// Re-save the file | |
workbook.save(dataDir + "MergeFiles1_out.xls"); |