map) throws Exception {
+ for (int i = 0; i < paragraphs.size(); ++i) {
+ XWPFParagraph paragraph = (XWPFParagraph) paragraphs.get(i);
+ if (paragraph.getText().indexOf("{{") != -1) {
+ this.parseThisParagraph(paragraph, map);
+ }
+ }
+ }
+
+ /**
+ * 核心替换方法
+ *
+ * 段落处理段落,执行替换的情况
+ *
+ * @param paragraph
+ * @param currentRun
+ * @param currentText 当前内容
+ * @param runIndex 当前内容对应的下标
+ * @param map 要替换成的参数集合
+ * @throws Exception
+ */
private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText, List runIndex, Map map) throws Exception {
if (currentText.contains("fe:") && currentText.startsWith("{{")) {
currentText = currentText.replace("fe:", "").replace("{{", "").replace("}}", "");
@@ -37,7 +106,6 @@
} else {
PoiPublicUtil.setWordText(currentRun, objx.toString());
}
-
});
} else {
Object obj = PoiPublicUtil.getRealValue(currentText, map);
@@ -49,15 +117,15 @@
PoiPublicUtil.setWordText(currentRun, currentText);
}
}
-
for (int k = 0; k < runIndex.size(); ++k) {
((XWPFRun) paragraph.getRuns().get((Integer) runIndex.get(k))).setText("", 0);
}
-
runIndex.clear();
}
- private void checkThisTableCellIterator(List cells, Map map) throws Exception {
+ //先执行预匹配,获取最大的长度,在进行之下的扩容
+ private Boolean checkThisTableCellIterator(List cells, XWPFTable table,
+ Map map, int row, Integer maxExpansionLength, Integer differExpansionLength) throws Exception {
int cellIndex = 0;
while (cellIndex < cells.size()) {
String text = cells.get(cellIndex).getText().trim();
@@ -66,24 +134,191 @@
}
cellIndex++;
}
- if (cellIndex >= cells.size()) {
- return;
+ int currentIndex = cells.size() - 1;
+ //涉及扩容
+ while (cells.size() - currentIndex < differExpansionLength) {
+ cells.get(0).getTableRow().createCell();
+ }
+ //合并,且去除合并包含都是一列的情况
+ if (currentIndex + 1 < (maxExpansionLength - differExpansionLength)) {
+ //列合并
+ mergeCellsHorizontal(cells, currentIndex, currentIndex + differExpansionLength - 1);
+ }
+ if (cellIndex >= currentIndex) {
+ return false;
}
String text = cells.get(cellIndex).getText().trim();
+ return parseNextColAndAddCol(cells, text, cellIndex, map, table);
+ }
+
+
+ /**
+ * 解析列,并自动增加列
+ */
+ private Boolean parseNextColAndAddCol(List cells, String text, int cellIndex, Map map, XWPFTable table) throws Exception {
if (text != null && text.contains("fe:") && text.startsWith("{{")) {
text = text.replace("#fe:", "").replace("{{", "").replace("}}", "");
String[] keys = text.replaceAll("\\s{1,}", " ").trim().split(" ");
- String[] parmkeys = keys[0].split("\\.");
+ String[] paramKeys = keys[0].split("\\.");
Object result = PoiPublicUtil.getParamsValue(keys[0], map);
if (result instanceof List) {
List