Hi ,
Problem: Unable to create a Excel Workbook with 533 worksheet data using aspose api-- due to java.lang.OutOfMemoryError: Java heap space issue.
I have tried 3 different approach of creating a workbook with 533 worksheet data (No pivot table, chats etc... )
Approach # 1: Create a workbook - Loop to copy worksheet data from source worksheet data for 533 times fails on
com.aspose.cells.Worksheet(srcworksheet)
Approach # 2:
Open and Save Workbook with a source file1 containing 300 worksheet data.
And Open 2nd Workbook with source file 2 containing remaining 233 worksheet data.
But workbook.open fails with out of memory
Approach #3
Create and save data into bunch of files (6 files) Workbook files and save to file system.
Use workbook.combine api to combine all workbook data into one File
But same issue - Java heap space issue. -out of memory issue.(as Combine calls copy eventually...)
at java.lang.OutOfMemoryError.()V (Unknown Source)
at com.aspose.cells.ad.(II)V (Unknown Source)
at com.aspose.cells.Row.(Lcom/aspose/cells/Worksheet;I)V (Unknown Source)
at com.aspose.cells.Rows.a(Lcom/aspose/cells/Rows;)V (Unknown Source)
at com.aspose.cells.Worksheet.copy(Lcom/aspose/cells/Worksheet;)V (Unknown Source)
at com.aspose.cells.Workbook.combine(Lcom/aspose/cells/Workbook;)V (Unknown Source)
at aces.reporting.outputhandlers.XLSReportWorkbookService.splitDataIntoWorksheet(Ljava/lang/String;Laces/external/excel/Worksheet;Ljava/util/Map;Ljava/lang/Integer;Ljava/util/List;)V (XLSReportWorkbookService.java:315)
Here is the snippet of the code
String finalFile = "C:/LOADTEST/FinalCombinedReport.xlsx";
Workbook finalWorkbook = new AsposeWorkbook();
//listOfWorkbooks.size()== 5
finalWorkbook.getInternalWorkbook().open(listOfWorkbooks.get(0),FileFormatType.XLSX);
for ( int bookCount = 1; bookCount < listOfWorkbooks.size(); bookCount++){
Workbook srcWorkbook = new AsposeWorkbook();
srcWorkbook.getInternalWorkbook().open(listOfWorkbooks.get(bookCount),FileFormatType.XLSX);
finalWorkbook.getInternalWorkbook().combine(srcWorkbook.getInternalWorkbook());
}
finalWorkbook.getInternalWorkbook().save(finalFile,FileFormatType.XLSX);
}
Thanks for the help in advance!