ParoTech
ParoTech

Reputation: 347

Writing 1 million records to an excel file

I am trying to write 1 million rows to and excel file using Java (I have to create an xls or xlsx).

Both Jxl and POI seem to be in-memory APIs, i.e both the apis will have the entire file of 1 million rows in the memory at a time. This will end up in consuming Java heap space. How can I read the records into the excel file? Thanks in advance.

Upvotes: 4

Views: 4603

Answers (2)

agad
agad

Reputation: 2189

JExcel can write excel files with help of temporary files instead of storing all the data in memory. You can enable it with following code:

WorkbookSettings settings = new WorkbookSettings();
settings.setGCDisabled( true );
settings.setUseTemporaryFileDuringWrite( true );   
settings.setTemporaryFileDuringWriteDirectory(tmpDir);
Workbook wb = Workbook.createWorkbook(os, settings);

Upvotes: 1

Jayan
Jayan

Reputation: 18459

apache-poi has a streaming api and can work with large data. I have used it till 500k. It may work for you with a million.

Upvotes: 3

Related Questions