POI和jxl.jar性能比较

JXL.jar  http://www.andykhan.com/jexcelapi/download.html  下载地址

优点:

Jxl对中文支持非常好,操作简单,方法看名知意。

Jxl是纯javaAPI,在跨平台上表现的非常完美,代码可以再windows或者Linux上运行而无需重新编写

支持Excel 95-2000的所有版本

生成Excel 2000标准格式

支持字体、数字、日期操作

能够修饰单元格属性

支持图像和图表,但是这套API对图形和图表的支持很有限,而且仅仅识别PNG格式

缺点:效率低,图片支持部完善,对格式的支持不如POI强大

POI,http://www.apache.org/dyn/closer.cgi/jakarta/poi/ 下载poi

1.       效率高,这点很好

2.       支持公式,宏,一些企业应用上会非常实用

3.       能够修饰单元格属性

4.       支持字体、数字、日期操作

缺点:不成熟,代码不能跨平台,貌似不少同行在使用工程中还碰到让人郁闷的BUG

--------------------------------性能测试------------------------------------------------

jxl包:好像是1.4 低于2.0 (忘记了)

poi:poi-3.5-FINAL-20090928.jar

环境:CPU:Intel(R) Core(TM)2 Duo CPU T65702.1GHZ ,2GB内存 MyEclipse1.6  JDK1.6

先前做过一些关于POI和jxl效率的比较,但是由于那时候测试工具很简单,不标准,偶尔在网上获得以为网友提供的简单测试包,还不错。所以重新测试下POI和JXL的性能

创建代码如下:

/**
 * poi 创xcel
 */
public void writerPOI() {
    try {        
        long dir= (long) Math.round(Math.floor(Math.random() * 10000000));
        String dirPath = "c://11//".concat(String.valueOf(dir)) ;
        File file = new File(dirPath);
        if(file.exists()) {
            System.out.println(file.getName()+"存oi");
            if(file.delete()) {
                file.mkdir();
            }                
        }else {
            file.mkdir();
        }
        // 创xcel 工
        HSSFWorkbook newbook = new HSSFWorkbook();
        int j = 0;
        while(j < sheet){ //控heet创
            HSSFSheet sheet = newbook.createSheet("test"+j);
            HSSFRow row = null ;//行
            HSSFCell cell1 = null ;//列
            HSSFCell cell2 = null ;//列
            for(int i = 0 ; i < leng ; i ++){
                row = sheet.createRow(i) ;
                cell1 = row.createCell(0);//列
                cell2 = row.createCell(1);//列
                if(cell1 == null){
                    System.out.println("cell1 null ");
                }
                cell1.setCellType(HSSFCell.CELL_TYPE_STRING);// 定        
                cell1.setCellValue("A数OI"+i);// 在
                cell2.setCellType(HSSFCell.CELL_TYPE_STRING);// 定        
                cell2.setCellValue("B数OI"+1);// 在
            }
            j++ ;
        }
        // 新
         long l = (long) Math.round(Math.floor(Math.random() * 10000000));
        String name = "poi_".concat(String.valueOf(l)).concat(".xls");
        FileOutputStream fp = new FileOutputStream(dirPath.concat("//").concat(name));            
        newbook.write(fp);// 把xcel 工
        fp.flush();            
        fp.close();// 操
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Jxl代码:

/**
 * jxl 创xcel
 */
public void writerJXL() {
    try {
        long dir= (long) Math.round(Math.floor(Math.random() * 10000000));
        String dirPath ="c://11//".concat(String.valueOf(dir)) ;
        File file = new File(dirPath);
        if(file.exists()) {
            System.out.println(file.getName()+"存xl");
            if(file.delete()) {
                file.mkdir();
            }
 
        }else {
            file.mkdir();
        }
        //      打   
        long l = (long) Math.round(Math.floor(Math.random() * 1000000000));
        String name = "jxl_".concat(String.valueOf(l)).concat(".xls");
        WritableWorkbook book = Workbook.createWorkbook( new  File(dirPath.concat("//").concat(name)));
        int j = 0 ;
        while(j < sheet){ //控heet创
            WritableSheet sheet  =  book.createSheet("test"+j ,j);
            Label label1 = null ;
            Label label2 = null ;
            for(int i = 0 ; i < leng ;i ++){
                label1  =   new  Label(0,i,"A数xl"+i ); //第第
                label2  =   new  Label(1,i,"A数xl"+i );            
                sheet.addCell(label1);    //  将    
                sheet.addCell(label2);               
            }
            j++ ;
        }        
        book.write();
        book.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RowsExceededException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (WriteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }    
}

 

 测试数据和结果如下:

 

一个sheet,逐渐增加数据量
sheet行数300060001200020000
poi avg(ms)11.1628.9246.28171.9
jxl avg(ms)29.7624.2225.9943.06
poi total(ms)55.8144.6231,41859.5
jxl total(ms)148.79121.08129.96215.29
poi tps93.0835.3122.556.98
jxl tps33.7747.4847.3625.23
poi内存占用(kb)11081.9418653.2342613.3353047.9
jxl内存占用(kb)7033.9270385724.467,030.30
  1个sheet  

测试结果图:

 pj1

pjn1

每个sheet 6000条数据逐渐增加sheet个数

sheet个数1234
poi avg(ms)30.5260.3441.0791.23
jxl avg(ms)31.2222.7525.6227.89
poi total(ms)152.6301.69205.38456.13
jxl total(ms)156.1113.79128.09139.46
poi tps24.4717.8924.5111.01
jxl tps42.2145.0450.9544.78
poi内存占用(kb)18016.57199449.0152980.453882.59
jxl内存占用(kb)5727.597469.649235.399,236.00
  6000条/sheet  

 

pj2 pjn2

测试结论:

1. poi已消耗内存换取部分效率,而jxl在内存消耗上一直很稳定。POI很容易内存溢出

2.poi随着数据量的增大,性能直线下降,当我增大到24000条每个sheet的时候,内存溢出。jxl却能运行

建议在大数据量的时候使用jxl .可以保证效率和较小内存消耗。在具体开发中,对部分常用的excel下载,可生产副本文件,避免重复生产Excel消耗内存

3.在测试的过程中,发现POI极其不稳定。获得的数据有时候相差特别大。每种测试情况我是重复测试4次,然后取平均值

  • 12
    点赞
  • 60
    收藏
    觉得还不错? 一键收藏
  • 18
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值