包头进度bug修复
This commit is contained in:
parent
27713a831c
commit
75a2e82efa
@ -730,7 +730,6 @@ public class PlanRecordServiceImpl extends ServiceImpl<PlanRecordMapper, PlanRec
|
|||||||
String templateUrl = Fileutils.getExportTemplateFile("excel/进度检测体系模板.xlsx").getAbsolutePath();
|
String templateUrl = Fileutils.getExportTemplateFile("excel/进度检测体系模板.xlsx").getAbsolutePath();
|
||||||
// String templateUrl = "C:\\Users\\Administrator\\Desktop\\进度检测体系模板.xlsx";
|
// String templateUrl = "C:\\Users\\Administrator\\Desktop\\进度检测体系模板.xlsx";
|
||||||
TemplateExportParams template = new TemplateExportParams(templateUrl, map.keySet().toArray(new Integer[]{}));
|
TemplateExportParams template = new TemplateExportParams(templateUrl, map.keySet().toArray(new Integer[]{}));
|
||||||
|
|
||||||
ExcelUtils.downLoadFormulaExcel("导出.xlsx", response, map, template);
|
ExcelUtils.downLoadFormulaExcel("导出.xlsx", response, map, template);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -750,7 +749,6 @@ public class PlanRecordServiceImpl extends ServiceImpl<PlanRecordMapper, PlanRec
|
|||||||
planRecords = planRecords.stream().filter(planRecord -> Objects.equals(planRecord.getWorkType(), 2)).collect(Collectors.toList());
|
planRecords = planRecords.stream().filter(planRecord -> Objects.equals(planRecord.getWorkType(), 2)).collect(Collectors.toList());
|
||||||
List<PlanRecord> tree = BeanUtil.copyToList(ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(planRecords)), "id", "parentId", "children"), PlanRecord.class);
|
List<PlanRecord> tree = BeanUtil.copyToList(ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(planRecords)), "id", "parentId", "children"), PlanRecord.class);
|
||||||
planRecords = ListUtils.treeToList(tree, "id", "parentId", "children", "0");
|
planRecords = ListUtils.treeToList(tree, "id", "parentId", "children", "0");
|
||||||
// List<PlanRecord> list = treeToList(top);
|
|
||||||
PlanRecord ePlanRecord = null;
|
PlanRecord ePlanRecord = null;
|
||||||
PlanRecord pPlanRecord = null;
|
PlanRecord pPlanRecord = null;
|
||||||
PlanRecord cPlanRecord = null;
|
PlanRecord cPlanRecord = null;
|
||||||
@ -801,10 +799,11 @@ public class PlanRecordServiceImpl extends ServiceImpl<PlanRecordMapper, PlanRec
|
|||||||
*/
|
*/
|
||||||
private void putMajorMap(Map<Integer, Map<String, Object>> root, List<PlanRecord> planRecords, PlanRecord parent, int sheetIndex) {
|
private void putMajorMap(Map<Integer, Map<String, Object>> root, List<PlanRecord> planRecords, PlanRecord parent, int sheetIndex) {
|
||||||
Map<String, Object> threeMap = new HashMap<>(15);
|
Map<String, Object> threeMap = new HashMap<>(15);
|
||||||
|
List<Map<String, Object>> listMap = new ArrayList<>();
|
||||||
|
threeMap.put("listMap", listMap);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
threeMap.put("jobName1", "单元名称:" + parent.getJobName());
|
threeMap.put("jobName1", "单元名称:" + parent.getJobName());
|
||||||
List<PlanRecord> list = planRecords.stream().filter(planRecord -> planRecord.getAncestors().contains(parent.getId() + "")).collect(Collectors.toList());
|
List<PlanRecord> list = planRecords.stream().filter(planRecord -> planRecord.getAncestors().contains(parent.getId() + "")).collect(Collectors.toList());
|
||||||
List<Map<String, Object>> listMap = new ArrayList<>();
|
|
||||||
for (PlanRecord record : list) {
|
for (PlanRecord record : list) {
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("code1", record.getJobName());
|
map.put("code1", record.getJobName());
|
||||||
@ -818,23 +817,11 @@ public class PlanRecordServiceImpl extends ServiceImpl<PlanRecordMapper, PlanRec
|
|||||||
map.put("lastTotalActualPer0", "" + NumberUtils.formatXlsDecimalPer(record.getLastTotalActualPer()));
|
map.put("lastTotalActualPer0", "" + NumberUtils.formatXlsDecimalPer(record.getLastTotalActualPer()));
|
||||||
listMap.add(map);
|
listMap.add(map);
|
||||||
}
|
}
|
||||||
threeMap.put("listMap", listMap);
|
threeMap.put("sum", "=SUM(D6:D" + (list.size() + 7) + ")/2");
|
||||||
threeMap.put("sum", "=SUM(D6:D" + (list.size() + 8) + ")/2");
|
|
||||||
}
|
}
|
||||||
root.put(sheetIndex, threeMap);
|
root.put(sheetIndex, threeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PlanRecord> treeToList(PlanRecord top) {
|
|
||||||
List<PlanRecord> children = top.getChildren();
|
|
||||||
if (children == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (PlanRecord child : children) {
|
|
||||||
treeToList(child);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存单元数据 1.E单元;2.P单元;3.C单元;4.S单元
|
* 保存单元数据 1.E单元;2.P单元;3.C单元;4.S单元
|
||||||
*
|
*
|
||||||
|
|||||||
@ -57,22 +57,43 @@ public class ExcelUtils {
|
|||||||
public static void downLoadFormulaExcel(String fileName, HttpServletResponse response, Map<Integer, Map<String, Object>> map, TemplateExportParams template) throws IOException {
|
public static void downLoadFormulaExcel(String fileName, HttpServletResponse response, Map<Integer, Map<String, Object>> map, TemplateExportParams template) throws IOException {
|
||||||
Workbook workbook = ExcelExportUtil.exportExcel(map, template);
|
Workbook workbook = ExcelExportUtil.exportExcel(map, template);
|
||||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||||
evaluator.evaluateAll();
|
|
||||||
// for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
||||||
// Sheet sheet = workbook.getSheetAt(sheetNum);
|
Sheet sheet = workbook.getSheetAt(sheetNum);
|
||||||
// for (Row r : sheet) {
|
for (Row r : sheet) {
|
||||||
// for (Cell c : r) {
|
for (Cell c : r) {
|
||||||
// if (c != null) {
|
if (c == null) continue;
|
||||||
// String cell = c.getCellFormula();
|
|
||||||
// if (cell.indexOf("=") == 0) {
|
// 仅处理字符串类型的单元格
|
||||||
// c.setCellFormula(cell.substring(1));
|
if (c.getCellType() == CellType.STRING) {
|
||||||
// evaluator.evaluate(c);
|
String value = c.getStringCellValue();
|
||||||
// }
|
if (value.startsWith("=")) {
|
||||||
// }
|
// 设置公式
|
||||||
// }
|
String formula = value.substring(1);
|
||||||
// }
|
try {
|
||||||
// }
|
c.setCellFormula(formula);
|
||||||
workbook.setForceFormulaRecalculation(true); // 强制公式自动计算
|
} 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);
|
downLoadExcel(fileName, response, workbook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user