github地址:https://github.com/alibaba/easyexcel;
参考网址:https://alibaba-easyexcel.github.io/index.html
引入jar:
<!-- 阿里巴巴 easyExcel依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
页面请求:<a href="/easyExcelUtil/getExportData" target="_blank">EasyExcel导出测试</a>
/** * 页面导出 * @param */ @GetMapping(value = "/daochuStatisticToExcel") @ResponseBody public Object daochuStatisticToExcel(HttpServletRequest request, HttpServletResponse response) throws Exception { try { List list = getDataList(); String fileName = new String("文件名称.xlsx".getBytes(), "ISO-8859-1"); response.addHeader("Content-Disposition", "filename=" + fileName); ServletOutputStream out = response.getOutputStream(); EasyExcelFactory.write(out,ExcelData.class).sheet("文件标签名称").doWrite(list); } catch (Exception e) { e.printStackTrace(); log.error(e.toString(), e); } return null; }
@Data public class SwitchStatisticData extends BaseRowModel { @ExcelProperty({"总标题", "日期标题"}) private Date tDate;//日期 @ExcelProperty({"总标题", "数量"}) private Long countNum;//数量 @ExcelProperty({"总标题", "内容"}) private String count;//内容 }