Easy Poi 导出多sheet页

效果

在这里插入图片描述

代码

	@GetMapping("/export")
    @ApiOperation(value ="多sheet导出", produces = "application/octet-stream")
    public void export(HttpServletResponse response) {
        List<Map<String, Object>> sheetInfos = new ArrayList<>();


        // sheet1的导出设置信息。
        ExportParams sheet1ExportParam = new ExportParams();
        sheet1ExportParam.setSheetName("sheet1的名字");
        Map<String, Object> sheet1ExportInfo = new HashMap<>();
        // title里面是ExportParams对象
        sheet1ExportInfo.put("title", sheet1ExportParam);
        // entity 对应的导出的实体
        sheet1ExportInfo.put("entity", ExcelDTO1.class);
        // data 是对应的导出的数据--
        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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值