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;//內容 }