diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java index 4879c80b5..3ecc063ea 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java @@ -30,6 +30,7 @@ import com.jero.modules.cert.template.enums.ParamsIsMustEnum; import com.jero.modules.ocr.util.LineHumpUtil; import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; +import com.jero.modules.project.util.Docx4jUtils; import com.jero.modules.project.util.ExcelUtil; import com.jero.modules.project.util.WordUtil; import com.jero.modules.split.common.ReadExcel; @@ -48,6 +49,7 @@ import org.docx4j.Docx4J; import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; +import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mock.web.MockMultipartFile; @@ -785,6 +787,8 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl> fileListAll = (List>) allParamsInfoList.get(2).get("fileListAll"); @@ -838,7 +842,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl 0) { + sb.append("#"); + } + sb.append(s1); + appender.append(sb.toString()); + continue; + } + //被分离的数据一般都是'${'这样被分开 + //匹配以'$'开头的变量找到'}' 得到索引位置 + int i1 = s1.indexOf("}"); + //先切割得到这个完整体 + String substr = s1.substring(0, i1 + 1); + //把变量追加到StringBuilder + sb.append(substr.replaceAll("\n","").replaceAll("<[^>]+>", "")); + //再将标签数据追加到StringBuilder包裹变量 + sb.append(s1.substring(i1 + 1)); + + appender.append(sb.toString()); + } + + return appender.toString(); + } + /** * 清扫 docx4j 模板变量字符,通常以${variable}形式 *

diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java index 4d66e753e..b492d8057 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java @@ -59,6 +59,11 @@ public class WordUtil { documentPart.variableReplace((HashMap) map); } + public static void replaceVariableWithOutClear(WordprocessingMLPackage wordMLPackage, Map map) throws Exception { + MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); + documentPart.variableReplace((HashMap) map); + } + public static void replaceTable(String templatePath, int tableNum, int rowNum, List> dataList, String outPath) throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(templatePath)); MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart(); @@ -203,7 +208,6 @@ public class WordUtil { public static void replacePictureBatch(WordprocessingMLPackage wordMLPackage, List> picList) throws Exception { try { MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart(); - Docx4jUtils.cleanDocumentPart(mainDocumentPart); Document wmlDoc = (Document)mainDocumentPart.getJaxbElement(); Body body = wmlDoc.getBody(); List textList = getAllPlaceholderElementFromObject(body); // 获取文档中所有占位符 @@ -241,7 +245,6 @@ public class WordUtil { */ public static Map filterParams(WordprocessingMLPackage wordMLPackage, Map params) throws Exception { MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart(); - Docx4jUtils.cleanDocumentPart(mainDocumentPart); Document wmlDoc = (Document)mainDocumentPart.getJaxbElement(); Body body = wmlDoc.getBody(); List textList = getAllPlaceholderElementFromObject(body); // 获取文档中所有占位符