AutosizeColumns on SXSSFWorkbook

2019-02-16 11:50发布

Is it possible to autoSizeColumns on a streaming SXSSFWorkbook? I implemented an export functionality to export a list of objects to excel. At first I used the XSSFWorkbook (not streaming) and after all the cells were created, I autosized all the columns, resulting in a nice excel file.

For performance issues we wanted to change the workbook to the streaming version, but this resulted in a NullPointer at org.apache.poi.ss.util.SheetUtil.getCellWidth.

Is it possible to call autoSizeColumns for a SXSSFWorkbook?

Im using poi-ooxml 3.9, but I have the same issue in 3.8.

1条回答
\"骚年 ilove
2楼-- · 2019-02-16 12:11

You need to make sure every cell has a value.

We use the following code to set a string value to a cell:

Cell c = row.createCell(i);
c.setCellValue(text == null ? "" : text );
查看更多
登录 后发表回答