大数据导出POI之SXSSFWorkbook

https://www.jianshu.com/p/df05c7fd6fa8

POI还有SXSSFWorkbook专门处理大数据

OutputStream os = null;  
try {  
    HttpServletResponse response = super.getResponse();  
    response.setContentType("application/force-download"); // 设置下载类型  
    String filename ="risk_event.xlsx";  
    response.setHeader("Content-Disposition","attachment;filename=" + filename); // 设置文件的名称  
    os = response.getOutputStream(); // 输出流  
    SXSSFWorkbook wb = new SXSSFWorkbook(1000);//内存中保留 1000 条数据,以免内存溢出,其余写入 硬盘  
       //获得该工作区的第一个sheet     
    Sheet sheet1 = wb.createSheet("sheet1");   
       int excelRow = 0;  
       //标题行  
       Row titleRow = (Row) sheet1.createRow(excelRow++);  
    for (int i = 0; i < columnList.size(); i++) {  
        Cell cell = titleRow.createCell(i);    
              cell.setCellValue(columnList.get(i));  
    }  
      
    for (int m = 0; m < cycleCount; m++) {  
        List<List<String>> eventStrList = this.convertPageModelStrList();  
        if (eventStrList!= null && eventStrList.size() > 0) {  
            for (int i = 0; i < eventStrList.size(); i++) {  
                //明细行  
                Row contentRow = (Row) sheet1.createRow(excelRow++);  
                List<String> reParam = (List<String>) eventStrList.get(i);  
                for (int j = 0; j < reParam.size(); j++) {  
                    Cell cell = contentRow.createCell(j);    
                    cell.setCellValue(reParam.get(j));  
                }  
            }  
        }  
    }  
    wb.write(os);  
} catch (Exception e) {  
    e.printStackTrace();  
} finally {  
    try {  
        if (os != null) {  
            os.close();  
        }  
    } catch (IOException e) {  
        e.printStackTrace();  
    } // 关闭输出流  
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值