Apache Poi slow on generate xlsx file

2019-07-29 11:38发布

问题:

I switched from HSSFWorkbook to XssFWorkbook and the performance on create Excel are going down. I search and search and I find that the bad performance, on create xlsx, is a known problem. If i try to create a file with about 1000 rows takes 3-4 minutes, is too much.

Is there a solution to improve speed?

Thanks!

回答1:

Are you using "autoSizeColumn"? If so this can cause an extreme bottleneck if you try to do it after each cell insertion. Put it after all the data is in the table, then do something like this:

for(int i=0;i<numberOfRows; i++){
        workbook.getSheetAt(0).autoSizeColumn(i);
    }