From f693c796a404be89db19f7ee6457cd44cd697d0c Mon Sep 17 00:00:00 2001 From: liyawei Date: Mon, 10 Oct 2022 17:36:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=BA=93-=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89word=E5=AF=BC=E5=87=BA-=E8=A7=A3=E5=86=B3=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E4=B8=AD=E9=99=A4=E5=8D=A0=E4=BD=8D=E7=AC=A6=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E5=85=B6=E4=BB=96=E6=96=87=E6=9C=AC=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ParamsReportDetailEOServiceImpl.java | 3 + .../jero/modules/project/util/WordUtil.java | 57 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java index 3ecc063ea..9528cf673 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java @@ -1263,6 +1263,9 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl configIdList = Arrays.asList(paramsReportDetailVO.getConfigIds().split(",")); // 需要导出的配置列 List> dataList = paramsReportDetailEOMapper.listInfoForExport(idList, paramsReportDetailVO); // 查询需要导出的数据 + dataList = dataList.stream().collect(Collectors.collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(p -> (String) p.get("id")))), + ArrayList::new)); // 去重 List paramsConfigEOList = paramsReportConfigEOService.queryList(paramsReportDetailVO.getParamsManifestId()); // 查询所有配置列 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 b492d8057..e21195135 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 @@ -189,7 +189,7 @@ public class WordUtil { Drawing drawing = factory.createDrawing(); drawing.getAnchorOrInline().add(inline); run.getContent().add(drawing); - replaceTextToImage(bm, text, wordMLPackage, bytes); + replaceTextToImage(bm, "\\$\\{" + key + "\\}", text, wordMLPackage, bytes); } } } catch (Exception var17) { @@ -218,7 +218,7 @@ public class WordUtil { byte[] bytes = (byte[]) picMap.get("bytes"); for(Text bm : textList) { - if (bm.getValue().equals("${" + key + "}")) { + if (bm.getValue().contains("${" + key + "}")) { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline("", "", 0, 1, true); ObjectFactory factory = new ObjectFactory(); @@ -226,7 +226,7 @@ public class WordUtil { Drawing drawing = factory.createDrawing(); drawing.getAnchorOrInline().add(inline); run.getContent().add(drawing); - replaceTextToImage(bm, text, wordMLPackage, bytes); + replaceTextToImage(bm, "\\$\\{" + key + "\\}", text, wordMLPackage, bytes); } } } @@ -387,7 +387,7 @@ public class WordUtil { * @throws Exception * @author liyawei */ - public static void replaceTextToImage(Text bm, Object object, WordprocessingMLPackage wordMLPackage , byte[] bytes) throws Exception { + public static void replaceTextToImage(Text bm, String key, Object object, WordprocessingMLPackage wordMLPackage , byte[] bytes) throws Exception { if (wordMLPackage == null) { return; } @@ -423,16 +423,49 @@ public class WordUtil { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline("", "", 0, 1, true); ObjectFactory factory = Context.getWmlObjectFactory(); - R run = factory.createR(); +// R run = factory.createR(); Drawing drawing = factory.createDrawing(); - if(text != null){ - Text txt = factory.createText(); - txt.setValue(text); - run.getContent().add(txt); + + for(int j=0;j0 && !valueStr[k-1].equals("#")) { + Text txt = factory.createText(); + txt.setValue(values.substring(index, k)); + r.getContent().add(txt); + } + + if (text != null) { + Text txtp = factory.createText(); + txtp.setValue(text); + r.getContent().add(txtp); + } + r.getContent().add(drawing); + drawing.getAnchorOrInline().add(inline); + index = k + 1; + } + + } + + if(!values.endsWith("#")) { + Text txt = factory.createText(); + txt.setValue(values.substring(index)); + r.getContent().add(txt); + } + + theList.add(rangeStart, r); // 添加图片到原占位符位置 } else { return;