- 浏览: 7257635 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1546)
- 企业中间件 (236)
- 企业应用面临的问题 (236)
- 小布Oracle学习笔记汇总 (36)
- Spring 开发应用 (54)
- IBatis开发应用 (16)
- Oracle基础学习 (23)
- struts2.0 (41)
- JVM&ClassLoader&GC (16)
- JQuery的开发应用 (17)
- WebService的开发应用 (21)
- Java&Socket (44)
- 开源组件的应用 (254)
- 常用Javascript的开发应用 (28)
- J2EE开发技术指南 (163)
- EJB3开发应用 (11)
- GIS&Mobile&MAP (36)
- SWT-GEF-RCP (52)
- 算法&数据结构 (6)
- Apache开源组件研究 (62)
- Hibernate 学习应用 (57)
- java并发编程 (59)
- MySQL&Mongodb&MS/SQL (15)
- Oracle数据库实验室 (55)
- 搜索引擎的开发应用 (34)
- 软件工程师笔试经典 (14)
- 其他杂项 (10)
- AndroidPn& MQTT&C2DM&推技术 (29)
- ActiveMQ学习和研究 (38)
- Google技术应用开发和API分析 (11)
- flex的学习总结 (59)
- 项目中一点总结 (20)
- java疑惑 java面向对象编程 (28)
- Android 开发学习 (133)
- linux和UNIX的总结 (37)
- Titanium学习总结 (20)
- JQueryMobile学习总结 (34)
- Phonegap学习总结 (32)
- HTML5学习总结 (41)
- JeeCMS研究和理解分析 (9)
最新评论
-
lgh1992314:
[u][i][b][flash=200,200][url][i ...
看看mybatis 源代码 -
尼古拉斯.fwp:
图片根本就不出来好吧。。。。。。
Android文件图片上传的详细讲解(一)HTTP multipart/form-data 上传报文格式实现手机端上传 -
ln94223:
第一个应该用排它网关吧 怎么是并行网关, 并行网关是所有exe ...
工作流Activiti的学习总结(八)Activiti自动执行的应用 -
ZY199266:
获取不到任何消息信息,请问这是什么原因呢?
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息 -
xiaoyao霄:
DestinationSourceMonitor 报错 应该导 ...
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息
在POI3.8中SXSSF仅仅支持excel2007格式是对XSSF的一种流的扩展。目的在生成excel时候,需要生成大量的数据的时候,通过刷新的方式将excel内存信息刷新到硬盘的方式,提供写入数据的效率。
官方原文如下:
SXSSF (Streaming Usermodel API)
SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limite d. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.
You can specify the window size at workbook construction time via new SXSSFWorkbook(int windowSize) or you can set it per-sheet via SXSSFSheet#setRandomAccessWindowSize(int windowSize)
When a new row is created via createRow() and the total number of unflushed records would exceed the specified window size, then the row with the lowest index value is flushed a nd cannot be accessed via getRow() anymore.
The default window size is 100 and defined by SXSSFWorkbook.DEFAULT_WINDOW_SIZE.
A windowSize of -1 indicates unlimited access. In this case all records that have not been flushed by a call to flushRows() are available for random access.
The example below writes a sheet with a window of 100 rows. When the row count reaches 101, the row with rownum=0 is flushed to disk and removed from memory, when rownum reaches 102 then the row with rownum=1 is flushed, etc.
测试代码如下:
package com.easyway.excel.events.stream; import java.io.FileOutputStream; 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; /** * SXSSF (Streaming Usermodel API) * 当文件写入的流特别的大时候,会将内存中数据刷新flush到硬盘中,减少内存的使用量。 * 起到以空间换时间作用,提供效率。 * * @Title: * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company:易程科技股份有限公司 * @Date:2012-6-17 * @author longgangbai * @version 1.0 */ public class SXSSExcelEvent { public static void main(String[] args) throws Throwable { //创建基于stream的工作薄对象的 Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk //SXSSFWorkbook wb = new SXSSFWorkbook(); //wb.setCompressTempFiles(true); // temp files will be gzipped Sheet sh = wb.createSheet(); //使用createRow将信息写在内存中。 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 //当使用getRow方法访问的时候,将内存中的信息刷新到硬盘中去。 for(int rownum = 0; rownum < 900; rownum++){ System.out.println(sh.getRow(rownum)); } // ther last 100 rows are still in memory for(int rownum = 900; rownum < 1000; rownum++){ System.out.println(sh.getRow(rownum)); } //写入文件中 FileOutputStream out = new FileOutputStream("C://sxssf.xlsx"); wb.write(out); //关闭文件流对象 out.close(); System.out.println("基于流写入执行完毕!"); } }
SXSSF flushes sheet data in temporary files (a temp file per sheet) and the size of these temporary files can grow to a very large value . For example, for a 20 MB csv data the size of the temp xml becomes more than a gigabyte. If the size of the temp files is an issue, you can tell SXSSF to use gzip compression:
SXSSFWorkbook wb = new SXSSFWorkbook();
wb.setCompressTempFiles(true); // temp files will be gzipped
评论
//当使用getRow方法访问的时候,将内存中的信息刷新到硬盘中去。
什么意思,不使用这个方法getRow()就不可以释放内存么?必须调用一下去释放吗?
奥 明白了,楼主是为了输出,看一下 是否为null,从而确定已经从内存中释放掉了。原来的是这么写的:
// Rows with rownum < 900 are flushed and not accessible
for (int rownum = 0; rownum < 900; rownum++) {
Assert.assertNull(sh.getRow(rownum));
Assert.assertNull(sh1.getRow(rownum));
}
// ther last 100 rows are still in memory
for (int rownum = 900; rownum < 1000; rownum++) {
Assert.assertNotNull(sh.getRow(rownum));
Assert.assertNotNull(sh1.getRow(rownum));
}
//当使用getRow方法访问的时候,将内存中的信息刷新到硬盘中去。
什么意思,不使用这个方法getRow()就不可以释放内存么?必须调用一下去释放吗?
不好意思,我没有尝试,起始100W行这样的大数据量的话,最好循环刷新到硬盘,减少内存使用。我是这样的理解。希望继续沟通!
发表评论
-
【转】Django resources
2014-01-23 14:35 10719Django resources This page li ... -
使用国内镜像源来加速python pypi包的安装
2014-01-16 11:16 197579pipy国内镜像目前有: http://pypi.d ... -
[转 ]vagrant使用简介
2014-01-10 13:53 256191> 简介: vagrant提供了易于配置,重复性 ... -
[转]在Java中调用Python
2014-01-07 13:08 9144在执行之前都需要把jython对应的包加载进去,这个是必须的 ... -
[转]Jython初探
2014-01-07 11:19 2358转载自: ... -
[转]Eclipse配置PyDev插件
2014-01-02 14:25 2786安装python解释器 安装PyDev: 首 ... -
RestFuse的研究(五) Http请求的封装
2014-06-14 15:50 3521在RestFuse中封装了Http请 ... -
RestFuse的研究(四) Junit的Statement的分析
2013-12-06 11:46 1610在RestFuse提供了多种单 ... -
RestFuse的研究(三) Junit的Rule的使用和分析
2013-12-06 11:01 2194在junit中定义一些可以公用的规则(R ... -
RestFuse的研究(二) Junit的Runner的分类和模式
2013-12-06 10:40 1561在Junit4中的调用JunitCore可以采 ... -
RestFuse的研究(一) HttpJunitRunner的实现
2013-12-06 10:11 1698在RestFuse是一种针对Rest We ... -
[转]An open-source JUnit extension to test HTTP/REST APIs
2013-12-06 09:57 1055http://developer.eclipsesource ... -
TestNG简单的学习(十三)TestNG中Junit的实现
2013-12-04 09:00 3292TestNG和junit的整合 ... -
TestNG简单的学习(十二)TestNG运行
2013-12-03 09:08 51456文档来自官方地址: ... -
TestNG简单的学习(十一)TestNG学习总结
2013-12-03 09:08 14000最近一直在学习关于TestNG方面的知识,根 ... -
TestNG简单的学习(十)TestNG @Listeners 的使用
2013-12-03 09:07 8630TestNG官方网站: http://testng.or ... -
TestNG简单的学习(九)TestNG Method Interceptors 的使用
2013-12-03 09:07 2662TestNG官方网站: http://testng ... -
TestNG简单的学习(八)TestNG Annotation Transformers 的使用
2013-12-03 09:07 2762TestNG官方网站: http://testng.or ... -
TestNG简单的学习(七)TestNG编程方式运行
2013-12-02 09:22 2402TestNG官方网站: http://testng.or ... -
TestNG简单的学习(六)测试工厂注释的使用
2013-12-02 09:22 2720TestNG官方网站: http://testng.or ...
相关推荐
poi-src-3.8-beta5-20111217.tar.gz
内部包括poi-3.8-20120326.jar、poi-ooxml-3.8-20120326.jar、poi-ooxml-schemas-3.8-20120326.jar 测试可用版本,有些下载的不能用
excl上传 poi-ooxml-schemas-3.8,poi-3.8,poi-ooxml jar包合集
poi-3.8-beta3-20110606,poi-examples-3.8-beta3-20110606
POI-HSSF和POI-XSSF和SXSSF(自POI 3.8 beta3起)-用于访问Microsoft Excel格式文件
java中读取word文档需要引用apache的poi开源项目...为方便下载提供6个jar包,其中包含:poi-3.8.jar;poi-ooxml-3.8.jar;poi-ooxml-schemas-3.8.jar;poi-scratchpad-3.8.jar;xmlbeans-2.3.0.jar;dom4j-1.6.1.jar。
POI最新版 3.8-beta4-20110826 可以实现解析word excel ppt等
poi-3.8-20120326-6个jar包: poi-3.8-20120326.jar poi-examples-3.8-20120326.jar poi-excelant-3.8-20120326.jar poi-ooxml-3.8-20120326.jar poi-ooxml-schemas-3.8-20120326.jar poi-scratchpad-3.8-20120326....
赠送原API文档:poi-ooxml-4.1.2-javadoc.jar; 赠送源代码:poi-ooxml-4.1.2-sources.jar; 赠送Maven依赖信息文件:poi-ooxml-4.1.2.pom; 包含翻译后的API文档:poi-ooxml-4.1.2-javadoc-API文档-中文(简体)版....
赠送原API文档:poi-ooxml-3.16-javadoc.jar; 赠送源代码:poi-ooxml-3.16-sources.jar; 赠送Maven依赖信息文件:poi-ooxml-3.16.pom; 包含翻译后的API文档:poi-ooxml-3.16-javadoc-API文档-中文(简体)版.zip; ...
用户poi开发,将excel中的数据导入到数据库中所用的jar包。poi-3.8-20120326.jar 和 poi-excelant-3.8-20120326.jar
poi3.8jar包一套+poi-pdf1.0和poi-core1.0两个jar包,网上搜索的代码就是需要这些jar包才能不借助第三方工具word转PDF
poi-3.8-final-jdk1.4-20120520-rc1.jar
赠送原API文档:poi-ooxml-5.2.0-javadoc.jar; 赠送源代码:poi-ooxml-5.2.0-sources.jar; 赠送Maven依赖信息文件:poi-ooxml-5.2.0.pom; 包含翻译后的API文档:poi-ooxml-5.2.0-javadoc-API文档-中文(简体)-英语...
poi-3.8.jar poi-examples-3.8.jar poi-ooxml-3.8.jar poi-ooxml-schemas-3.8.jar poi-scratchpad-3.8.jar
赠送原API文档:poi-ooxml-3.17-javadoc.jar; 赠送源代码:poi-ooxml-3.17-sources.jar; 赠送Maven依赖信息文件:poi-ooxml-3.17.pom; 包含翻译后的API文档:poi-ooxml-3.17-javadoc-API文档-中文(简体)版.zip; ...
NULL 博文链接:https://topmanopensource.iteye.com/blog/1562322
导入excel需要的\poi-ooxml-schemas-3.8-20120326.jar
赠送原API文档:poi-ooxml-4.1.2-javadoc.jar; 赠送源代码:poi-ooxml-4.1.2-sources.jar; 赠送Maven依赖信息文件:poi-ooxml-4.1.2.pom; 包含翻译后的API文档:poi-ooxml-4.1.2-javadoc-API文档-中文(简体)-英语...
赠送原API文档:poi-scratchpad-4.1.2-javadoc.jar; 赠送源代码:poi-scratchpad-4.1.2-sources.jar; 赠送Maven依赖信息文件:poi-scratchpad-4.1.2.pom; 包含翻译后的API文档:poi-scratchpad-4.1.2-javadoc-API...