easypoi使用

easypoi使用


cn.afterturn
easypoi-base
3.0.1


cn.afterturn
easypoi-web
3.0.1


cn.afterturn
easypoi-annotation
3.0.1

/**
 * 快递导出
 * @param expStoreQueryParam
 * @param response
 * @throws Exception
 */
@RequestMapping("exportExpStore")
public void exportExpStore(ExpStoreQueryParam expStoreQueryParam, HttpServletResponse response) throws Exception {
    if (StringUtils.isEmpty(expStoreQueryParam.getStartDate())
            || StringUtils.isEmpty(expStoreQueryParam.getEndDate())) {
        expStoreQueryParam.setStartDate(DateUtil.getLastWeekSameDay());
        expStoreQueryParam.setEndDate(DateUtil.getToday());
    }
    Workbook workbook = null;
    ExportParams params = new ExportParams("快递信息导出", "快递信息导出");
    Integer count = expStoreService.getExpCount(expStoreQueryParam);
    count = count==null?0:count;
    int totalPage = (int)Math.ceil((double)count/10000);
    for (int i=1;i<=totalPage;i++) {
        expStoreQueryParam.setPage(i + "");
        expStoreQueryParam.setLimit(10000 + "");
        PageUtils page = expStoreService.queryPageExportVO(BeanUtil.bean2map(expStoreQueryParam));
        workbook = ExcelExportUtil.exportBigExcel(params, ExpStoreVO.class, page.getList());
        page.getList().clear();
    }
    if(count==0){
        workbook = ExcelExportUtil.exportBigExcel(params, ExpStoreVO.class, new ArrayList<ExpStoreVO>());
    }
    ExcelExportUtil.closeExportBigExcel();
    String fileName = "快递信息导出.xlsx";
    ExportUtil.downloadExcel(fileName, workbook, response);
}





public static void downloadExcel(String filename, Workbook workbook, HttpServletResponse response) throws Exception {
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
    outputStream.flush();
    outputStream.close();
}

//处理大数据批量导出使用此方法,for循环分页组装数据,减轻一下查询数十万条数据带来的数据库压力问题,减少对应的内存消耗,以流的方式响应给前台,

**坑:版本问题可能导致各种报错,建议使用上述版本

http://easypoi.mydoc.io/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值