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循环分页组装数据,减轻一下查询数十万条数据带来的数据库压力问题,减少对应的内存消耗,以流的方式响应给前台,
**坑:版本问题可能导致各种报错,建议使用上述版本