Commit 449f71e1 by lijingjing

新增行未带入公式问题修改;

优化匹配公式
parent c54d2839
...@@ -10,7 +10,10 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator; ...@@ -10,7 +10,10 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*; import org.apache.poi.xssf.usermodel.*;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class SingleSheetMoreItemOperation implements Operation { public class SingleSheetMoreItemOperation implements Operation {
...@@ -81,6 +84,9 @@ public class SingleSheetMoreItemOperation implements Operation { ...@@ -81,6 +84,9 @@ public class SingleSheetMoreItemOperation implements Operation {
XSSFRow hideRow = sheetOne.getRow(beginRow - 1); XSSFRow hideRow = sheetOne.getRow(beginRow - 1);
XSSFRow zeroRow = sheetOne.getRow(beginRow); XSSFRow zeroRow = sheetOne.getRow(beginRow);
int lastCellNum = zeroRow.getLastCellNum(); int lastCellNum = zeroRow.getLastCellNum();
// 提取属性对应公式
Map<String, String> formulaMap = this.configList.stream().filter(t -> Objects.nonNull(t.getFormula()))
.collect(Collectors.toMap(OriginalTemplateConfig::getAttributeName, OriginalTemplateConfig::getFormula));
int insertCount = voList.size() - templateSampleNum; int insertCount = voList.size() - templateSampleNum;
for (int m = 0; m < insertCount; m++) { for (int m = 0; m < insertCount; m++) {
...@@ -95,8 +101,9 @@ public class SingleSheetMoreItemOperation implements Operation { ...@@ -95,8 +101,9 @@ public class SingleSheetMoreItemOperation implements Operation {
// 根据标题行处理公式 // 根据标题行处理公式
// 若标题(Si%等等)为空,那么不进行处理,如若不为空,再根据是否存在公式进行处理 // 若标题(Si%等等)为空,那么不进行处理,如若不为空,再根据是否存在公式进行处理
String title = hideRow.getCell(j).getStringCellValue(); String title = hideRow.getCell(j).getStringCellValue();
if (StringUtils.isNotBlank(title)) { if (StringUtils.isNotBlank(title) && formulaMap.containsKey(title.trim())) {
xssfCell.setCellFormula(getCellFormula(title.trim(), newRowIndex + m)); String formula = formulaMap.get(title.trim());
xssfCell.setCellFormula(OriginalUtil.initFormula(formula, newRowIndex + m));
} }
} }
insertRow++; insertRow++;
...@@ -239,15 +246,4 @@ public class SingleSheetMoreItemOperation implements Operation { ...@@ -239,15 +246,4 @@ public class SingleSheetMoreItemOperation implements Operation {
} }
} }
} }
private String getCellFormula(String key, int rowIndex) {
Optional<OriginalTemplateConfig> optional = this.configList.stream().filter(t -> Objects.equals(key, t.getAttributeName())).findAny();
if (optional.isPresent()) {
String formula = optional.get().getFormula();
if (StringUtils.isNotBlank(formula)) {
return OriginalUtil.initFormula(formula, rowIndex);
}
}
return null;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment