EasyExcel导出多sheet页

实现效果

 

依赖项

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel-core</artifactId>
            <version>3.2.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.2.1</version>
            <scope>compile</scope>
        </dependency>

controller层

    @PostMapping("/export")
    public void export(HttpServletResponse response, String vin) throws IOException {
        service.excelTest(response, vin);
    }

serviceImpl

    @Override
    public void excelTest(HttpServletResponse response, String vin) {
        // 车身信息
        PlanCarInfo planCarInfos = stopMapper.getPlanCarInfoByVin(vin);
        // 过点记录
        List<AviPassRecordDTO> aviPassRecords = stopMapper.getAviPassRecordInfoByVin(vin);
        // 化验参数
        List<QualityParamAssayDTO> paramAssConfigs = assayService.findAllParamAssConfigInfo(vin);

        Map<String,Object> map = new HashMap<>();
        map.put("carType",planCarInfos.getBodyType());
        map.put("carColor",planCarInfos.getColorType());
        map.put("carConfig",planCarInfos.getConfigType());
        map.put("tpsCode",planCarInfos.getTpsCode());
        map.put("vin",planCarInfos.getVin());
//

        response.addHeader("Content-Disposition", "filename=" + "模板导出.xlsx");
        //设置类型,扩展名为.xls
        response.setContentType("application/vnd.ms-excel");

        ExcelWriter writer = null;
        try {
            // 车身信息 + 过点记录
            writer = EasyExcel.write(response.getOutputStream()).withTemplate(new ClassPathResource("质量追踪.xlsx").getInputStream()).build();
            WriteSheet writeSheet1 = EasyExcel.writerSheet(0).build();
            writer.fill(map, writeSheet1);
            writer.fill(aviPassRecords, writeSheet1);
            // 化验参数
            WriteSheet writeSheet2 = EasyExcel.writerSheet(1).head(QualityParamAssayDTO.class).build();
            writer.write(paramAssConfigs,writeSheet2);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (writer != null) {
                writer.finish();
            }
        }
    }

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值