1.对于一些重要的数据,导出excle表格时需要对表格加密,使用excleExcel加密超级简单
public void taxesQuery(HttpServletResponse response, ArrayList<TaskTaxesQuery> taxesQueryList){
try {
LocalDate dateNow = LocalDate.now();
//response输出文件流
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(dateNow+"报表".xls", "UTF-8"));
//构建excelWriter
@Cleanup("finish") ExcelWriter writer = EasyExcel
//将数据映射到TaskTaxesQuery实体类并响应到浏览器
.write(new BufferedOutputStream(response.getOutputStream()),TaskTaxesQuery.class)
//自动关闭输出流
.autoCloseStream(Boolean.TRUE)
//excel版本,强烈建议导出07版excel,因为省内存
.excelType(ExcelTypeEnum.XLS)
//是否需要表头
.needHead(Boolean.TRUE)
//设置excel保护密码
.password("1234")
//构建
.build();
//初始化sheet
WriteSheet writeSheet = EasyExcel.writerSheet().build();
writeSheet.setSheetName(dateNow+"报表");
//导出excel,注意导出结束要finish
writer.write(taxesQueryList,writeSheet);
}catch (Exception e){
logger.error(e);
}finally {
}
}