easyExcel的动态头导出

前言

easyExcel遇到动态头的导出,直接上代码。

List<ChronicForCrowdVo> chronicForCrowdVos = getRegularStatisticsByPopulation(chronicReportByDeptParam);
        List<List<String>> total = new ArrayList<>();
        chronicForCrowdVos.forEach(x -> {
            List<String> list = new ArrayList<>();
            list.add(x.getTypeValue());
            for (int i = 0; i < x.getNumber().size(); i++) {
                list.add(x.getNumber().get(i).getManNumber().toString());
                list.add(x.getNumber().get(i).getWomanNumber().toString());
            }
            total.add(list);
        });

        List<List<String>> list = new ArrayList<List<String>>();
        List<String> head0 = new ArrayList<>();
        head0.add("职业");
        list.add(head0);


        List<String> productHead = new ArrayList<>();
        productHead.add("男");
        productHead.add("女");

        List<String> head1 = new ArrayList<>();
        for (int i = 0; i < chronicForCrowdVos.get(0).getNumber().size(); i++) {
            for (String s : productHead) {
                head1 = new ArrayList<>();
                head1.add(chronicForCrowdVos.get(0).getNumber().get(i).getName());
                head1.add(s);
                list.add(head1);
            }
        }

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment; filename*=utf-8''" + "慢病分地区定时统计");
        OutputStream os = response.getOutputStream();

        EasyExcel.write(os)
                // 这里放入动态头
                .head(list).sheet("模板")
                // 当然这里数据也可以用 List> 去传入
                .doWrite(total);

结果:
easyExcel的动态头导出_第1张图片

你可能感兴趣的:(java,pdf,excel)