From e5ff3230beb29fe11d4c12923e53706c122da455 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Tue, 19 Mar 2024 14:09:55 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=AF=BC=E5=87=BA=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=85=E9=93=BE=E6=8E=A5=EF=BC=88=E7=BB=B4?= =?UTF-8?q?=E4=BF=9D=E8=AE=B0=E5=BD=95/=E4=BC=9A=E8=AE=AE=E8=AE=B0?= =?UTF-8?q?=E5=BD=95/=E5=9F=B9=E8=AE=AD=E8=AE=B0=E5=BD=95/=E8=80=83?= =?UTF-8?q?=E8=AF=95=E8=AE=B0=E5=BD=95/=E6=BC=94=E7=BB=83=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CarCheckRecordServiceImpl.java | 2 +- .../service/impl/CarMaintenanceServiceImpl.java | 2 +- .../service/impl/CarUsedRecordServiceImpl.java | 2 +- .../service/impl/ConferenceRecordServiceImpl.java | 2 +- .../service/impl/HygieneRecordServiceImpl.java | 2 +- .../service/impl/RehearsalRecordServiceImpl.java | 2 +- .../service/impl/TrainRecordServiceImpl.java | 2 +- .../com/hnac/hzims/safeproduct/utils/BaseUtil.java | 58 +++++++++++++++++++--- 8 files changed, 57 insertions(+), 15 deletions(-) diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java index 6c55284..3330e59 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java @@ -208,7 +208,7 @@ public class CarCheckRecordServiceImpl extends ServiceImpl params, String wordPath, String pdfPath, HttpServletResponse response) { + public static void exportDocument(String templateFile, Map params, String wordPath, String pdfPath,String findName, HttpServletResponse response) { try { List res = new ArrayList<>(); - XWPFDocument document = BaseUtil.fillDocument(templateFile, params); + XWPFDocument document = BaseUtil.fillDocument(templateFile, params,findName); res.add(document); BaseUtil.exportWord(res, wordPath); } catch (Exception e) { @@ -112,15 +114,55 @@ public class BaseUtil { * @param params 数据参数 * @return 文件 */ - public static XWPFDocument fillDocument(String templatePath, Map params) { + public static XWPFDocument fillDocument(String templatePath, Map params, String findName) { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); + if (StringUtils.isNotEmpty(findName)) { + String findText = params.get(findName).toString(); + if (StringUtils.isNotEmpty(findText)) { + JSONArray jsonArray = new JSONArray(findText); + for (XWPFTable table : xwpfDocument.getTables()) { + for (int row = 0; row < table.getNumberOfRows(); row++) { + for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) { + XWPFTableCell cell = table.getRow(row).getCell(col); + for (XWPFParagraph p : cell.getParagraphs()) { + Iterator iterator = p.getRuns().iterator(); + while (iterator.hasNext()) { + XWPFRun r = iterator.next(); + String text = r.getText(0); + if (findText.equals(text)) { + r.setText("", 0); // 清除原有文本 + XWPFParagraph paragraph = r.getParagraph(); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + String name = jsonObject.getString("name"); + String url = jsonObject.getString("url"); + String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId(); + CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); + cLink.setId(id); + CTText ctText = CTText.Factory.newInstance(); + ctText.setStringValue(name); + CTR ctr = CTR.Factory.newInstance(); + ctr.setTArray(new CTText[]{ctText}); + cLink.setRArray(new CTR[]{ctr}); + if(i