导出文件
easyexcel 导出文件
实体类
@Data @Accessors(chain = true) public class RefDeptExcelDTO { @ExcelProperty({"一"}) @ColumnWidth(20) private String dept1; @ExcelProperty({"二"}) @ColumnWidth(20) private String dept2; @ExcelProperty({"三"}) @ColumnWidth(20) private String dept3; @ExcelProperty({"四"}) @ColumnWidth(20) private String dept4; @ExcelProperty({"五"}) @ColumnWidth(20) private String dept5; }
导出代码
setResponseCommonParams(response, fileName); ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).inMemory(true).build(); WriteSheet writeSheet = EasyExcel.writerSheet(i, sheetList.get(i).getSheetName()) .head(sheetList.get(i).getHead()) .build(); excelWriter.write(sheetList.get(i).getSourceList(), writeSheet); excelWriter.finish();
或者
EasyExcel.write(response.getOutputStream(), head).sheet(sheetName).doWrite(sourceList);