I want to generate a xlsx file with 600,000 rows or above, 20 columns in one worksheet. But after the program ran about 20 minutes, the OutOfMemoryError was throwed. The program is attached.
I am using Aspose.Cells 7.0.1 for Java. My CPU is 2.20GHz, and JVM argument setting is "-Xmx1280M".
How much memory does it need? Are there any mistakes in my program? Or is there any optimization to make my program generate the Excel file successfully under the limitation of memory of 1280 MB? Or is there a disk swap mechanism (dump memory to disk and then load it back separately) can be used?
For your application, we recommend you to use LightCells APIs to save the xlsx file because your cells data set is very large.
Attached is a demo application to create the same xlsx file with your original application by LightCells APIs. It needs less than 1G memory to create the desired xlsx file.
We have fixed the issue of NullPointerException for LightCells. Please try the new fix. And another notable thing in your program is that the “sheetCount” variable is useless in fact.
LightCellsDataProvider.startSheet(int sheetIndex) will be invoked for every existing worksheet only. In your program you created one new Workbook and then save it, in such situation you only have one worksheet in the workbook and LightCellsDataProvider.startSheet(int sheetIndex) will be called only once with sheet index 0 even if you set the “sheetCount” as more than 1. To create sheet data for multiple worksheets, you should create those worksheets before saving the workbook, code like following: Workbook wb = new Workbook(); wb.getWorksheets().add(…); wb.getWorksheets().add(…); … wb.save(…);
I have modified my program as what you told me above to make the "sheetCount" variable useful, and tested it by using Aspose.Cells for Java v7.0.1.6. The result xlsx file is ok.