We use Apache POI to export lists of drawing deliveries to excel files. To overcome the limitation of 65.535 rows per file with xls (Excel 97) we introduced xlsx (Excel 2007) support which allows for up to 1.048.575 rows. In addition to the increased amount of data which has to be handled, we encountered increased memory consumption by XMLBeans which is used by POI for creation of the xlsx document tree. The bigger memory footprint of xssf compared to hssf model is a well-known problem. In POI 3.5 there was an example included demonstrating a workaround for big tables: BigGridDemo.java
This example amazingly works around the POI library, actually using it only to generate a container xml file and then streaming the content as plain text into the appropriate xml part of the xlsx zip archive. Of course it would be much nicer to leave the knowledge about the file format enclosed in the library, but POI isn’t able to write to streams on the fly. By adapting the big grid demo it is possible to write directly to the http servlet response:
-
Enumeration<ZipEntry> templateEntries = templateZip.entries();
-
try {
-
while (templateEntries.hasMoreElements()) {
-
// copy all template content to the ZipOutputStream zos
-
// except the sheet itself
-
}
-
try {
-
sheetOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-
sheetOut.write("<worksheet><sheetData>");
-
// write the content – rows and cells
-
sheetOut.write("</sheetData></worksheet>");
-
}
-
finally { sheetOut.close(); }
-
finally { zos.close(); }



