您的位置:首页 > 其它

使用Poi的HSSFWorkbook导出Excel大小限制,即内存溢出

2013-03-27 22:19 357 查看
这篇文章的主题是大致测试使用Poi的HSSFWorkbook到出Excel文件时,不在报内存溢出时能导出的最大的sheet与行数。

首先设置几个条件:

1.我们设置导出的excel内容如下:




这里有10列内容。对应代码如下:

row.createCell(1).setCellValue(1.2);

row.createCell(2).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(3).setCellValue(true);

row.createCell(4).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(5).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(6).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(7).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(8).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(9).setCellValue(createHelper.createRichTextString("This is a string"));

row.createCell(10).setCellValue(createHelper.createRichTextString("This is a string"));

2.设置java运行内存(VM arguments)

-Xms64m -Xmx256m -XX:MaxPermSize=256m

最后测试最大行数在166772~166872之间。

导出结果截图如下:



以上就是本篇文章主题。

以下内容为批注:

如果想用HSSFWorkbook导出更大行数的excel。那需要设置更大的运行内存,最大行数取决你的运行虚拟内存。

例如:

修改VM arguments为“-Xms64m -Xmx512m -XX:MaxPermSize=512m“,那么能导出最大的行数在333680~331680之间。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: