OutOfMemoryError when using apache POI API to write Excel file
Posted on 2005-04-06
I am using apache POI API in a Servlet to write data into an Excel (.xls) file then send to browsers. It work fine when the data is not much. But it give an java.lang.OutOfMemoryError when the data volume is high.
Then I have try JExcel API, it is more lightweight compare to POI where it is can support higher volume of data. But there is still a limit (26k of rows with 25 columns).
The main reason I found is that both API use the same mechanism to write Excel file: create an object to represent workbook --> add Sheets --> add Cells --> write to OutputStream.
so the workbook object will encapsule all data before it was write to OutputStream. This size of object will grow very fast when there is lots of data until OutOfMemoryError occurs.
Any suggstion to solve this problem besides configure JVM heap size(Since it will still have a limit) ? Thanks in advance.