diff --git a/src/main/java/com/zhgd/xmgl/modules/baotou/plan/service/impl/PlanRecordServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/baotou/plan/service/impl/PlanRecordServiceImpl.java index 4431592f9..b197c9bd8 100644 --- a/src/main/java/com/zhgd/xmgl/modules/baotou/plan/service/impl/PlanRecordServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/baotou/plan/service/impl/PlanRecordServiceImpl.java @@ -730,7 +730,6 @@ public class PlanRecordServiceImpl extends ServiceImpl Objects.equals(planRecord.getWorkType(), 2)).collect(Collectors.toList()); List tree = BeanUtil.copyToList(ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(planRecords)), "id", "parentId", "children"), PlanRecord.class); planRecords = ListUtils.treeToList(tree, "id", "parentId", "children", "0"); -// List list = treeToList(top); PlanRecord ePlanRecord = null; PlanRecord pPlanRecord = null; PlanRecord cPlanRecord = null; @@ -801,10 +799,11 @@ public class PlanRecordServiceImpl extends ServiceImpl> root, List planRecords, PlanRecord parent, int sheetIndex) { Map threeMap = new HashMap<>(15); + List> listMap = new ArrayList<>(); + threeMap.put("listMap", listMap); if (parent != null) { threeMap.put("jobName1", "单元名称:" + parent.getJobName()); List list = planRecords.stream().filter(planRecord -> planRecord.getAncestors().contains(parent.getId() + "")).collect(Collectors.toList()); - List> listMap = new ArrayList<>(); for (PlanRecord record : list) { HashMap map = new HashMap<>(); map.put("code1", record.getJobName()); @@ -818,23 +817,11 @@ public class PlanRecordServiceImpl extends ServiceImpl treeToList(PlanRecord top) { - List children = top.getChildren(); - if (children == null) { - return null; - } - for (PlanRecord child : children) { - treeToList(child); - } - return null; - } - /** * 保存单元数据 1.E单元;2.P单元;3.C单元;4.S单元 * diff --git a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java index acf701bd3..236de69dd 100644 --- a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java @@ -57,22 +57,43 @@ public class ExcelUtils { public static void downLoadFormulaExcel(String fileName, HttpServletResponse response, Map> map, TemplateExportParams template) throws IOException { Workbook workbook = ExcelExportUtil.exportExcel(map, template); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); - evaluator.evaluateAll(); -// for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) { -// Sheet sheet = workbook.getSheetAt(sheetNum); -// for (Row r : sheet) { -// for (Cell c : r) { -// if (c != null) { -// String cell = c.getCellFormula(); -// if (cell.indexOf("=") == 0) { -// c.setCellFormula(cell.substring(1)); -// evaluator.evaluate(c); -// } -// } -// } -// } -// } - workbook.setForceFormulaRecalculation(true); // 强制公式自动计算 + + for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) { + Sheet sheet = workbook.getSheetAt(sheetNum); + for (Row r : sheet) { + for (Cell c : r) { + if (c == null) continue; + + // 仅处理字符串类型的单元格 + if (c.getCellType() == CellType.STRING) { + String value = c.getStringCellValue(); + if (value.startsWith("=")) { + // 设置公式 + String formula = value.substring(1); + try { + c.setCellFormula(formula); + } catch (Exception e) { + // 处理公式错误,例如无效语法 + log.error("公式设置失败: " + formula); + continue; + } + + // 更改进样式为常规格式,避免Excel显示为文本 +// CellStyle style = workbook.createCellStyle(); +// style.cloneStyleFrom(c.getCellStyle()); +// style.setDataFormat((short)BuiltinFormats.getBuiltinFormat("General")); +// c.setCellStyle(style); + + // 计算公式结果并更新单元格类型 + evaluator.evaluateFormulaCell(c); + } + } + } + } + } + + // 强制Excel打开时重新计算公式 + workbook.setForceFormulaRecalculation(true); downLoadExcel(fileName, response, workbook); } diff --git a/src/main/resources/excel/进度检测体系模板.xlsx b/src/main/resources/excel/进度检测体系模板.xlsx index d8b8c81f3..462264e01 100644 Binary files a/src/main/resources/excel/进度检测体系模板.xlsx and b/src/main/resources/excel/进度检测体系模板.xlsx differ