How to speed up column automation in apache POI?

I use the following code to authorize columns in my table:

for (int i = 0; i < columns.size(); i++) { sheet.autoSizeColumn(i, true); sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 600); } 

The problem is that it takes more than 10 minutes to automatically sort each column with large tables with more than 3000 rows. However, it goes very fast for small documents. Is there anything that could help automate the work faster?

+16
java performance excel autosize apache-poi
Sep 24 '13 at 13:37
source share
1 answer

Solution that worked for me:

The merged areas could be avoided so that I can iterate over other cells and finally automatically sort into the largest cell, for example:

 int width = ((int)(maxNumCharacters * 1.14388)) * 256; sheet.setColumnWidth(i, width); 

where 1.14388 is the maximum width of the Serif font character and 256 font units.

Autosave performance improved from 10 minutes to 6 seconds.

+23
Sep 25 '13 at 14:09
source share



All Articles