SXSSFWorkbook上的AutosizeColumns [英] AutosizeColumns on SXSSFWorkbook
问题描述
是否可以在流式SXSSFWorkbook上使用autoSizeColumns? 我实现了导出功能,以将对象列表导出为excel.最初,我使用XSSFWorkbook(而不是流式传输),并且在创建所有单元格之后,我会自动调整所有列的大小,从而生成一个不错的excel文件.
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.
出于性能问题,我们希望将工作簿更改为流版本,但这导致在org.apache.poi.ss.util.SheetUtil.getCellWidth处出现NullPointer.
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.
是否可以为SXSSFWorkbook调用autoSizeColumns?
Is it possible to call autoSizeColumns for a SXSSFWorkbook?
我使用的是poi-ooxml 3.9,但在3.8版中我有同样的问题.
Im using poi-ooxml 3.9, but I have the same issue in 3.8.
推荐答案
您需要确保每个单元格都有一个值.
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 );
**单元格永远不能为null值,否则它将引发NullPointerException.因此,请按上面所示设置该值.
** Cell should never be null values else it throws NullPointerException. Hence set the value as shown above.
非常感谢,这很有帮助!
Thanks a lot, this helped!!
这篇关于SXSSFWorkbook上的AutosizeColumns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!