SXSSFWorkbook 上的 AutosizeColumns [英] AutosizeColumns on SXSSFWorkbook

查看:19
本文介绍了SXSSFWorkbook 上的 AutosizeColumns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在流式 SXSSFWorkbook 上自动调整大小列?我实现了一个导出功能,将对象列表导出到 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 );

** Cell 永远不应该是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆