Hutool-ExcelUtil多Sheet页导出

public void exportWritten(HttpServletResponse response, String projectKey) {
        //已填报计划表的组织
        Set<Map<String,Object>> orgList = ccpOrgMapper.getWrittenOrg(projectKey);
        //内容
        Set<Map<String,Object>> list1 = assessProjectMapper.getNrByJhb(projectKey);
        //细则
        Set<Map<String,Object>> list2 = assessProjectMapper.getXzByJhb(projectKey);
        list1.addAll(list2);

        String fileName = URLEncoder.encode("计划表考核总分汇总", StandardCharsets.UTF_8);
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");

        ExcelWriter writer = ExcelUtil.getWriter();
        //index 计数,excel的sheet页索引
        AtomicInteger index = new AtomicInteger();
        orgList.forEach(org->{
            //获取组织已经填写的计划表列表
            Set<Map<String,Object>> writeInfo = assessWriteMapper.getWrittenByProjectKey(org.get("org_code").toString(),projectKey);
            if (index.get() == 0) {
                //更改默认的sheet页命名
                writer.renameSheet(org.get("org_name").toString());
            } else {
                //创建新的sheet页
                writer.setSheet(org.get("org_name").toString());
            }
            List<Map<String,Object>> tempList = new ArrayList<>(list1);
            //设置表格标题
            writer.merge(8,tempList.get(0).get("jhbContent"));
            //设置表头
            writer.writeHeadRow(ListUtil.of("项目",
                    "内容",
                    "分值",
                    "考核标准",
                    "填报截止时间",
                    "填报内容",
                    "组织填报附件",
                    "打分截止时间",
                    "考核分"));
            //设置列宽
            writer.setColumnWidth(0,45);
            writer.setColumnWidth(1,45);
            writer.setColumnWidth(4,25);
            writer.setColumnWidth(7,25);

            //已填报计划表和计划表信息组装
            writeInfo.forEach(write -> list1.forEach(jhb->{
                if (write.get("nrKey").toString().equals(jhb.get("nrKey").toString())) {
                    List<Object> row = new ArrayList<>();
                    row.add(jhb.get("xmContent"));
                    row.add(jhb.get("nrContent"));
                    row.add(jhb.get("points"));
                    row.add(jhb.get("standard"));
                    row.add(jhb.get("upEndTime"));
                    row.add(write.get("writeContent"));
                    row.add(write.get("files"));
                    row.add(jhb.get("scoringEndTime"));
                    row.add(write.get("scoring"));
                    writer.writeRow(row);
                }
            }));
            index.getAndIncrement();
        });

        ServletOutputStream out = null;
        try {
            out = response.getOutputStream();
        } catch (IOException e) {
            log.error("导出失败!!",e);
            e.printStackTrace();
        }
        writer.flush(out, true);
        // 关闭writer,释放内存
        writer.close();
        //此处记得关闭输出Servlet流
        IoUtil.close(out);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值