POI 产生巨大 EXCEL 报表
时间:2011-08-28
来源:互联网
POI 产生巨大 EXCEL 报表
最近看 POI 的官网发现在产生 EXCEL 的部分有加入些新的东西:
再看看范例程式:
其中的吸引我的就在 SXSSFWorkbook 能设定要保存多少 rows 在记忆体中处理
这表示只要利用这个新的 API,我们就能在不耗费太多记忆体的情况下产生巨大的 EXCEL 档
最近看 POI 的官网发现在产生 EXCEL 的部分有加入些新的东西:
1 |
SXSSF is a brand new contribution and some features were added after it was first introduced in POI 3.8-beta3. Users are advised to try the latest build from trunk. Instructions how to build are here |
再看看范例程式:
1 |
import junit.framework.Assert; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.streaming.SXSSFWorkbook; public static void main(String[] args) throws Throwable { Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk Sheet sh = wb.createSheet(); for(int rownum = 0; rownum < 1000; rownum++){ Row row = sh.createRow(rownum); for(int cellnum = 0; cellnum < 10; cellnum++){ Cell cell = row.createCell(cellnum); String address = new CellReference(cell).formatAsString(); cell.setCellValue(address); } } // Rows with rownum < 900 are flushed and not accessible for(int rownum = 0; rownum < 900; rownum++){ Assert.assertNull(sh.getRow(rownum)); } // ther last 100 rows are still in memory for(int rownum = 900; rownum < 1000; rownum++){ Assert.assertNotNull(sh.getRow(rownum)); } FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx"); wb.write(out); out.close(); } |
其中的吸引我的就在 SXSSFWorkbook 能设定要保存多少 rows 在记忆体中处理
1 |
Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk |
这表示只要利用这个新的 API,我们就能在不耗费太多记忆体的情况下产生巨大的 EXCEL 档
作者: qrtt1 发布时间: 2011-08-28
Hi,不知道您有无遇过用此方式,在不同的sheet产生cell写入资料时,遇到问题?
我用此方式在多个sheet时,会遇到第2个以后的sheet,资料并没有写入.
不知道这是不是此API的限制?
我用此方式在多个sheet时,会遇到第2个以后的sheet,资料并没有写入.
不知道这是不是此API的限制?
作者: stevewan 发布时间: 2011-09-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28