easyexcel 表格数据组合填充 一个是map,一个通过list填充,list不为空时,导致下面的map填充的啥数据样式全都消失了

kkbh8khc  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(46)

建议先去看文档

快速开始常见问题

异常代码

double actCostSum=0.0;
                double stuCoreSumCost = (double)map.get("typeStuCoreSumCost");
                double medicineSumCost = (double)map.get("typeMedicineSumCost");
                double supSumCost = (double)map.get("typeSupSumCost");
                double otherSumCost = (double)map.get("typeOtherSumCost");
                double otherCoreActBedSum = (double)map.get("typeArticleSumCost");
                BigDecimal decimal = NumberUtil.add(stuCoreSumCost, medicineSumCost, supSumCost, otherSumCost, otherCoreActBedSum);
                actCostSum= decimal.doubleValue();
                map.put("actCostSum",actCostSum);
                // 附加总成本(赠药费用和人力成本)
                double preManCostSum=0.0;
                double mediSumCost =(double) map.get("typeFreeMediSumCost");
                double manSumCost = (double)map.get("typeManSumCost");
                preManCostSum = NumberUtil.add(mediSumCost, manSumCost);
                map.put("preManCostSum",preManCostSum);
                // 项目总费用(实际成本/+附加总成本)
                double proCostSum=0.0;
                proCostSum= NumberUtil.add(actCostSum,preManCostSum);
                map.put("proCostSum",proCostSum);

                // 逐年分解
                List<CtmsProYearResolve> ctmsProYearResolves = proYearResolveMapper.selectList(new LambdaQueryWrapperX<CtmsProYearResolve>()
                        .eq(CtmsProYearResolve::getProjectId, projectId));
                List<YearResolveExportVO> yearResolveExportVOS=new ArrayList<>();
                if(CollUtil.isNotEmpty(ctmsProYearResolves)){
                    for(CtmsProYearResolve resolve:ctmsProYearResolves){
                        YearResolveExportVO exportVO=new YearResolveExportVO();
                        double ratio = Double.parseDouble(resolve.getRatio()) / 100;
                        double sub = NumberUtil.mul(ratio, actCostSum);
                        double pre = NumberUtil.mul(ratio, preManCostSum);
                        double sum = NumberUtil.add(sub, pre);
                        exportVO.setRatio(resolve.getRatio()+"%");
                        exportVO.setExecuteYear(resolve.getExecuteYear());
                        exportVO.setActOutCostSum(String.valueOf(sub));
                        exportVO.setAdditionCostSum(String.valueOf(pre));
                        exportVO.setProYearCost(String.valueOf(sum));
                        yearResolveExportVOS.add(exportVO);
                    }
                }

                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                // 防止中文乱码
                String fileName = URLEncoder.encode("项目费用信息", "UTF-8")
                        .replaceAll("\\+","%20");
                response.setHeader("Content-disposition", "attachment;filename*=UTF-8''" + fileName + ExcelTypeEnum.XLSX.getValue());
                //响应的输出流
                 outputStream = response.getOutputStream();
                ClassPathResource classPathResource = new ClassPathResource("excel/projectCostConfig.xlsx");
                InputStream templateFileName = classPathResource.getInputStream();
                 //String fileName = "D://" + "proCostConfig" + System.currentTimeMillis() + "demo.xlsx";

                excelWriter = EasyExcel.write(outputStream).withTemplate(templateFileName).build();
                WriteSheet writeSheet = EasyExcel.writerSheet().build();
                FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();

                excelWriter.fill(new FillWrapper("year", yearResolveExportVOS),fillConfig, writeSheet);
                
                excelWriter.fill(map, writeSheet);

异常提示

大家尽量把问题一次性描述清楚,然后贴上全部异常,这样方便把问题一次性解决掉。
至少大家要符合一个原则就是,能让其他人复现出这个问题,如果无法复现,肯定无法解决。

问题描述

数据list有数据 下面的样式数据全都消失,,变成空白表格了,list为空,下面的map数据填充 正常填充 图一是模版 图二是list有数据的时候,图三是list为空的的时候

fquxozlt

fquxozlt1#

// 导出 Excel
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 防止中文乱码
String fileName = URLEncoder.encode("项目费用信息", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=UTF-8''" + fileName + ExcelTypeEnum.XLSX.getValue());
// 响应的输出流
outputStream = response.getOutputStream();

// 获取模板文件流
ClassPathResource classPathResource = new ClassPathResource("excel/projectCostConfig.xlsx");
InputStream templateFileName = classPathResource.getInputStream();

// 创建 EasyExcelWriter
excelWriter = EasyExcel.write(outputStream).withTemplate(templateFileName).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();

// 填充样式数据
if (CollUtil.isNotEmpty(yearResolveExportVOS)) {
    excelWriter.fill(new FillWrapper("year", yearResolveExportVOS), fillConfig, writeSheet);
}

// 填充普通数据
excelWriter.fill(map, writeSheet);

// 关闭资源
excelWriter.finish();
outputStream.flush();
outputStream.close();
kyxcudwk

kyxcudwk2#

请问解决了吗 遇到同样的问题

相关问题