效果
代码
@GetMapping("/export")
@ApiOperation(value ="多sheet导出", produces = "application/octet-stream")
public void export(HttpServletResponse response) {
List<Map<String, Object>> sheetInfos = new ArrayList<>();
ExportParams sheet1ExportParam = new ExportParams();
sheet1ExportParam.setSheetName("sheet1的名字");
Map<String, Object> sheet1ExportInfo = new HashMap<>();
sheet1ExportInfo.put("title", sheet1ExportParam);
sheet1ExportInfo.put("entity", ExcelDTO1.class);
sheet1ExportInfo.put("data", Lists.newArrayList());
sheetInfos.add(sheet1ExportInfo);
ExportParams sheet2ExportParam = new ExportParams();
sheet2ExportParam.setSheetName("sheet2的名字");
Map<String, Object> sheet2ExportInfo = new HashMap<>();
sheet2ExportInfo.put("title", sheet2ExportParam);
sheet2ExportInfo.put("entity", ExcelDTO2.class);
sheet2ExportInfo.put("data", Lists.newArrayList());
sheetInfos.add(sheet2ExportInfo);
Workbook workbook = ExcelExportUtil.exportExcel(sheetInfos, ExcelType.HSSF);
ExcelUtils.buildExcelDocument("多sheet页导出", workbook, response);
}
@Data
public class ExcelDTO1{
@Excel(name = "列表1",orderNum = "1")
private String name;
@Excel(name = "列表2",orderNum = "1")
private String level;
}
@Data
public class ExcelDTO2{
@Excel(name = "字段1",orderNum = "1")
private String name;
@Excel(name = "字段2",orderNum = "2")
private String level;
@Excel(name = "字段3",orderNum = "3")
private String aaaa;
}