3.POI SXSSF导出大量数据实例
来源:互联网 发布:ubuntu镜像下载地址 编辑:程序博客网 时间:2024/05/15 00:00
1.下面的示例编写了一个包含100行窗口的工作表。 当行计数达到101时,将rownum = 0的行刷新到磁盘并从内存中删除,当rownum达到102时,则刷新rownum = 1的行等。
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.util.CellReference;import org.apache.poi.xssf.streaming.SXSSFSheet;import org.apache.poi.xssf.streaming.SXSSFWorkbook;import org.junit.Test;import com.esen.util.StrFunc;/** * 下面的示例编写了一个包含100行窗口的工作表。 * 当行计数达到101时,将rownum = 0的行刷新到磁盘并从内存中删除, * 当rownum达到102时,则刷新rownum = 1的行 * */public class SXSSF { @Test public void Test() throws Exception { long start1 = System.currentTimeMillis(); // keep 100 rows in memory, exceeding rows will be flushed to disk SXSSFWorkbook wb1 = new SXSSFWorkbook(100); for (int sheetnum = 0; sheetnum < 20; sheetnum++) { Sheet sh1 = wb1.createSheet(); for(int rownum = 0; rownum < 50000; rownum++){ Row row1 = sh1.createRow(rownum); for(int cellnum = 0; cellnum < 10; cellnum++){ Cell cell1 = row1.createCell(cellnum); String address1 = new CellReference(cell1).formatAsString(); cell1.setCellValue(address1); } } } FileOutputStream out1 = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\sxssf1.xlsx"); wb1.write(out1); out1.close(); wb1.dispose(); System.out.println("for循环内定义对象,耗时:" + StrFunc.formatTime(System.currentTimeMillis()-start1)); // for循环内定义对象,耗时:1分16秒698毫秒 // for循环内定义对象,耗时:1分18秒691毫秒 // for循环内定义对象,耗时:1分21秒567毫秒 // for循环内定义对象,耗时:1分17秒721毫秒 // for循环内定义对象,耗时:1分30秒48毫秒}
- 下一个示例关闭自动刷新(windowSize = -1),代码手动控制部分数据如何写入磁盘
/** * 关闭自动刷新(windowSize = -1) * 代码控制将部分满足要求的数据写入磁盘 * @throws Exception * */ @Test public void TestPartData () throws Exception { /** * turn off auto-flushing and accumulate all rows in memory * windowSize = -1表示关闭自动刷新 * 所有的行都存放在内存中 * */ SXSSFWorkbook wb = new SXSSFWorkbook(-1); // Sheet sh = wb.createSheet(); Row row = null; Cell cell = null; String address = null; for(int rownum = 0; rownum < 10000; rownum++){ row = sh.createRow(rownum); for(int cellnum = 0; cellnum < 10; cellnum++){ cell = row.createCell(cellnum); address = new CellReference(cell).formatAsString(); cell.setCellValue(address); } /** * manually control how rows are flushed to disk * 手动控制行如何刷新到磁盘 * */ if(rownum % 100 == 0) { /** * retain 100 last rows and flush all others * 保留最后一行并刷新所有其他行 * */ ((SXSSFSheet)sh).flushRows(100); /** * ((SXSSFSheet)sh).flushRows() is a shortcut for ((SXSSFSheet)sh).flushRows(0), * this method flushes all rows * ((SXSSFSheet)sh).flushRows()是((SXSSFSheet)sh).flushRows(0)的快捷方式, * 此方法flushRows()刷新所有行 * */ } } FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx"); wb.write(out); out.close(); /** * dispose of temporary files backing this workbook on disk * 处理在磁盘上备份此工作簿的临时文件 * SXSSF分配临时文件,您必须始终清除显式,通过调用dispose方法 * */ wb.dispose(); }
0 0
- 3.POI SXSSF导出大量数据实例
- 1.POI导出大量数据方法介绍-SXSSF
- Spring MVC 使用poi sxssf 导出excel 2007 的数据
- poi实现大量数据导出excel
- java poi导出excel大量数据
- poi-Excel导出数据实例
- POI导出大量数据的简单解决方案(附源码)
- POI导出大量数据的简单解决方案(附源码)
- 使用poi导出大量数据到excel遇到的问题
- poi导出大量数据(15万条没有问题)
- 3.11 poi导出大量数据(最多导入65536条)
- 使用Apache POI 导出大量数据 问题记录
- 2.POI SXSSF注意事项
- poi导入导出数据库表数据实例
- POI-----POI导出Excel实例
- POI读取excel大量数据
- CSV导出大量数据
- poi导出excel实例
- ural 1496
- Redis集群解决方案----JAVA应用
- 读写分离二
- Linux--闹钟信号
- faster rcnn可视化(修改demo.py保存网络中间结果)
- 3.POI SXSSF导出大量数据实例
- Android设备开机时间统计
- Android获取MAC地址大全
- 自定义 View 实现钟表效果
- 第14周实践-1 项目1 - 数组大折腾(1)
- String全解析
- PHP的CI框架集成Smarty的最佳方式
- laravel队列
- 百度地图覆盖物