读书人

OutExcel2007 v1.0.0 公布

发布时间: 2012-06-29 15:48:46 作者: rapoo

OutExcel2007 v1.0.0 发布

?

这个只是个测试版本...目前该版本.支持多sheet100W数据量的数据导出.

?

解决了Excel2007的格式导出大数据量内存溢出问题 ,

?

本工具,绝对不会出现内存溢出的问题,即使每个sheet100W数据量.导出100个这样sheet ,(100W*100 的数据量)

?

希望大家.有BUG就提..有不好的地方就说啊...

?

?

package com.asc.excel;import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;import java.text.SimpleDateFormat;import java.util.Date;import com.asc.excel.util.SpreadSheet;import com.asc.excel.xlsx.XlsxWorkbook;public class WorkTest {public static void main(String[] args) throws Exception {long start = System.currentTimeMillis();create();for(int i = 0 ; i < 10; i++){append();}long end = System.currentTimeMillis();System.out.println(new SimpleDateFormat("mm:ss.SSS").format(new Date(end - start)));}public static void append() throws Exception{Workbook wb = new XlsxWorkbook(new File("D:/Temp/tmp.xlsx"));Sheet sht1 = wb.getSheet("第一制药");int start = sht1.getLastRowSum() +1;SpreadSheet sp2 = sht1.getSpreadSheet();for(int i = start ; i < (start + 10); 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();}Sheet sht2 = wb.getSheet("中美1");if(sht2 == null){sht2 = wb.createSheet("中美1"); }SpreadSheet sp = sht2.getSpreadSheet();int start2 = sht2.getLastRowSum();for(int i = start2 ; i < (start2 + 10); 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();}wb.write();}public static void create() throws Exception{Workbook wb = new XlsxWorkbook();Sheet st1 = wb.createSheet("第一制药");Sheet st2 = wb.createSheet("中美");SpreadSheet sp = st1.getSpreadSheet();for(int i = 1 ; i < 5; i ++){sp.insertRow(i);sp.createCell(0, "你好---" + i + "!");sp.createCell(1, (double)232987+i);sp.createCell(2, "12345---" + 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();}SpreadSheet sp2 = st2.getSpreadSheet();for(int i = 1 ; i < 10; 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();}OutputStream os = new FileOutputStream(new File("D:/Temp/tmp.xlsx"));wb.write(os);}}QQ : 277215237版本已经更新,
比如在你的create中再增加一些代码如下:
FileOutputStream os2 = new FileOutputStream(new File("F:/Temp/tmp2.xlsx"));
Workbook wb2 = new XlsxWorkbook();
Sheet st3 = wb2.createSheet("test");
SpreadSheet sp3 = st3.getSpreadSheet();
for (int i = 1; i < 5; i++) {
sp3.insertRow(i);
sp3.createCell(0, "你好---" + i + "!");
sp3.createCell(1, (double) 232987 + i);
sp3.createCell(2, "12345---" + i + "!");
sp3.createCell(3, (double) 232987 + i);
sp3.createCell(4, "12345---" + i + "!");
sp3.createCell(5, (double) 232987 + i);
sp3.createCell(6, "12345---" + i + "!");
sp3.createCell(7, (double) 232987 + i);
sp3.endRow();
}
wb2.write(os2);

因为我用这个放入项目中 导出第一次没有问题 但是第二次就抛出同样的错误比如在你的create中再增加一些代码如下:
FileOutputStream os2 = new FileOutputStream(new File("F:/Temp/tmp2.xlsx"));
Workbook wb2 = new XlsxWorkbook();
Sheet st3 = wb2.createSheet("test");
SpreadSheet sp3 = st3.getSpreadSheet();
for (int i = 1; i < 5; i++) {
sp3.insertRow(i);
sp3.createCell(0, "你好---" + i + "!");
sp3.createCell(1, (double) 232987 + i);
sp3.createCell(2, "12345---" + i + "!");
sp3.createCell(3, (double) 232987 + i);
sp3.createCell(4, "12345---" + i + "!");
sp3.createCell(5, (double) 232987 + i);
sp3.createCell(6, "12345---" + i + "!");
sp3.createCell(7, (double) 232987 + i);
sp3.endRow();
}
wb2.write(os2);

因为我用这个放入项目中 导出第一次没有问题 但是第二次就抛出同样的错误

实在抱歉,这个是最初的1.0版本的.是有这个bug,
已经在后续版本(最新版本v1.4.4)中修复了.而且后续版本中速度已经提高一倍了.
6 楼 tuyuan 2012-05-12 zhangzhi13856 写道您那有这jar的源代码吗?能否放我瞅瞅。
QQ: 277215237

读书人网 >开源软件

热点推荐