POI 最新版本已经支持大数据量导出,而不会内存溢出了. 但是我测试了下.效率没有我这个高.而且CPU消耗比较高.
曾经放出过源码. 但是很多人,....哎不说了.这次关闭源码.
这个只是个正式版本...目前该版本.支持多sheet100W数据量的数据导出.
解决了Excel2007的格式导出大数据量内存溢出问题 ,
本工具,绝对不会出现内存溢出的问题,即使每个sheet100W数据量.导出100个这样sheet ,(100W*100 的数据量)
已近解决了多处BUG.再我公司大数据量系统导出里面已近运行了3个月了.没出现问题
下载的压缩包里面已近包含了下面的测试类了.
package com.test; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import com.tgseam.excel.Sheet; import com.tgseam.excel.WorkBook; import com.tgseam.excel.impl.XlsxWorkBook; import com.tgseam.excel.info.OutConstants; import com.tgseam.excel.util.Cell; public class WorkTest { public static void main(String[] args) { new Thread(){ @Override public void run(){ new WorkTest().runs("temp1.xlsx"); } }.start(); // new Thread(){ // // @Override // public void run(){ // new WorkTest().runs("temp2.xlsx"); // } // // }.start(); } public void runs(String name){ long start = System.currentTimeMillis(); try { create(name);//1W*2(sheet)=2W WorkBook wb = null; for(int i = 0 ; i < 1; i++){ wb = append(name, wb); System.out.println("i = "+i); } wb.write(); } catch (Exception e) { e.printStackTrace(); } long end = System.currentTimeMillis(); System.out.println("End Create Xlsx Time: "+new SimpleDateFormat("mm:ss.SSS").format(new Date(end - start))); } public WorkBook append(String name, WorkBook wb) throws Exception{ long startTime = System.currentTimeMillis(); if(wb == null){ wb = new XlsxWorkBook(new File("D:/Temp/" + name)); } Sheet sht1 = wb.getSheet("第\"一\"制药"); if(sht1 == null){ sht1 = wb.createSheet("第\"一\"制药"); } int start = sht1.getLastRowSum() +1; Cell sp2 = sht1.getCell(); for(int i = start ; i < (start + 10000); i ++){ sht1.setLastRowSum(i); sp2.insertRow(i); sp2.createCell(0, "" + i + "!"); sp2.createCell(1, (double)232987+i); sp2.createCell(2, "" + i + "!"); sp2.createCell(3, (double)232987+i); sp2.createCell(4, "12345---" + i + "!"); sp2.createCell(5, (double)232987+i); sp2.createCell(6, "12345---" + i + "!"); sp2.createCell(7, (double)232987+i); sp2.createCell(8, (double)232987+i); sp2.createCell(9, "12345---" + i + "!"); sp2.createCell(10, (double)232987+i); sp2.createCell(11, (double)232987+i); sp2.createCell(12, "" + i + "!"); sp2.createCell(13, (double)232987+i); sp2.createCell(14, "12345---" + i + "!"); sp2.createCell(15, (double)232987+i); sp2.createCell(16, "12345---" + i + "!"); sp2.createCell(17, (double)232987+i); sp2.createCell(18, (double)232987+i); sp2.createCell(19, "12345---" + i + "!"); sp2.createCell(20, (double)232987+i); sp2.endRow(); } /*Sheet sht2 = wb.getSheet("中美史克"); if(sht2 == null){ sht2 = wb.createSheet("中美史克"); } SpreadSheet sp = sht2.getSpreadSheet(); int start2 = sht2.getLastRowSum(); for(int i = start2 ; i < (start2 + 10000); i ++){ sp.insertRow(i); sp.createCell(0, "很好" + i + "!"); sp.createCell(1, (double)232987+i); sp.createCell(2, "车市重么" + i + "!"); sp.createCell(3, (double)232987+i); sp.createCell(4, "12345---" + i + "!"); sp.createCell(5, (double)232987+i); sp.createCell(6, "12345---" + i + "!"); sp.createCell(7, (double)232987+i); sp.endRow(); }*/ System.out.println("Append or Create Sheet Time: "+ new SimpleDateFormat("mm:ss.SSS").format(new Date(System.currentTimeMillis() - startTime))); // wb.write(); return wb; } public void create(String name) throws Exception{ long start = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); WorkBook wb = new XlsxWorkBook(); Sheet st1 = wb.createSheet("第\"一\"制药"+name); Cell sp = st1.getCell(); //insert head; sp.insertRow(0); sp.createCell(0, "心魔", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(1, "'擦汗魔", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(2, "眼角膜", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(3, "行李魔", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(4, "豆豆魔", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(5, "OUTPUT", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(6, "hand", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(7, "novd", OutConstants.STYLE_FGCOLOR_GRAY); sp.createCell(8, "可可魔", OutConstants.STYLE_FGCOLOR_GRAY); sp.endRow(); for(int i = 1 ; i < 10000; i ++){ sp.insertRow(i); sp.createCell(0, "年后" + i + "!"); sp.createCell(1, (double)23.2987); sp.createCell(2, 0); sp.createCell(3, (double)2329.87); sp.createCell(4, (double) -2329.87154514); sp.createCell(5, (long) 232987+i); sp.createCell(6, (long) -232987+i); sp.createCell(7, "0001"); sp.createCell(8, calendar, OutConstants.STYLE_DATE); sp.createCell(9, "12345---" + i + "!"); sp.createCell(10, (double)232987+i); sp.createCell(11, (double)232987+i); sp.createCell(12, "" + i + "!"); sp.createCell(13, (double)232987+i); sp.createCell(14, "12345---" + i + "!"); sp.createCell(15, (double)232987+i); sp.createCell(16, "12345---" + i + "!"); sp.createCell(17, (double)232987+i); sp.createCell(18, (double)232987+i); sp.createCell(19, "12345---" + i + "!"); sp.createCell(20, (double)232987+i); sp.endRow(); } /*Sheet st2 = wb.createSheet("中美史克"); SpreadSheet sp2 = st2.getSpreadSheet(); for(int i = 1 ; i < 10000; i ++){ sp2.insertRow(i); sp2.createCell(0, "你好" + i + "!"); sp2.createCell(1, (double)232987+i); sp2.createCell(2, "你们号码.." + i + "!"); sp2.createCell(3, (double)232987+i); sp2.createCell(4, "12345---" + i + "!"); sp2.createCell(5, (double)232987+i); sp2.createCell(6, "12345---" + i + "!"); sp2.createCell(7, (double)232987+i); sp2.endRow(); }*/ long end = System.currentTimeMillis(); System.out.println("Create Sheet Time: "+ new SimpleDateFormat("mm:ss.SSS").format(new Date(end - start))); OutputStream os = new FileOutputStream(new File("D:/Temp/"+name)); wb.write(os); } } QQ : 277215237 有BUG联系我啊.亲们