From 0fbf875aa0a24fcd6781061e4e85232821d72caf Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 11 二月 2023 09:45:23 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/helper/WordHelper.java | 238 +++++++++++++++++++++++++++-------------------- data/ts.sql | 4 2 files changed, 137 insertions(+), 105 deletions(-) diff --git a/data/ts.sql b/data/ts.sql index 6cf7afe..2935359 100644 --- a/data/ts.sql +++ b/data/ts.sql @@ -146,8 +146,8 @@ group by modular1,modular2 order by modular1 desc,modular2; -select * from lf.sys_operate where modular2 = '' -delete from lf.sys_operate where modular2 = '' +select * from lf.sys_operate where modular2 = '' or modular2 = '2' or modular2 is null; +delete from lf.sys_operate where modular2 = '' or modular2 = '2' or modular2 is null; diff --git a/src/main/java/com/lf/server/helper/WordHelper.java b/src/main/java/com/lf/server/helper/WordHelper.java index 311a543..5704e07 100644 --- a/src/main/java/com/lf/server/helper/WordHelper.java +++ b/src/main/java/com/lf/server/helper/WordHelper.java @@ -119,7 +119,7 @@ */ private static void insertData(XWPFTable table, List<String[]> addList) { for (int i = 1, c = addList.size(); i < c; i++) { - XWPFTableRow row = table.createRow(); + table.createRow(); } List<XWPFTableCell> oldCells = table.getRow(1).getTableCells(); @@ -133,10 +133,24 @@ XWPFTableCell newCell = tableCells.get(j); if (0 == i) { - newCell.setText(addList.get(i)[j]); + // newCell.setText(addList.get(i)[j]) + setCellText(newCell, addList.get(i)[j]); } else { setCellText(oldCell, newCell, addList.get(i)[j]); } + } + } + } + + /** + * 璁剧疆鍗曞厓鏍兼枃鏈� + */ + private static void setCellText(XWPFTableCell cell, String text) { + List<XWPFParagraph> paragraphs = cell.getParagraphs(); + for (XWPFParagraph paragraph : paragraphs) { + List<XWPFRun> runs = paragraph.getRuns(); + for (XWPFRun run : runs) { + run.setText(text, 0); } } } @@ -194,42 +208,7 @@ cellR.setText(text); // 澶嶅埗瀛椾綋淇℃伅 - if (tmpR != null) { - if (!cellR.isBold()) { - cellR.setBold(tmpR.isBold()); - } - cellR.setItalic(tmpR.isItalic()); - cellR.setUnderline(tmpR.getUnderline()); - cellR.setColor(tmpR.getColor()); - cellR.setTextPosition(tmpR.getTextPosition()); - if (tmpR.getFontSize() != -1) { - cellR.setFontSize(tmpR.getFontSize()); - } - if (tmpR.getFontFamily() != null) { - cellR.setFontFamily(tmpR.getFontFamily()); - } - if (tmpR.getCTR() != null) { - if (tmpR.getCTR().isSetRPr()) { - CTRPr tmpRpr = tmpR.getCTR().getRPr(); - if (tmpRpr.isSetRFonts()) { - CTFonts tmpFonts = tmpRpr.getRFonts(); - CTRPr cellRpr = cellR.getCTR().isSetRPr() ? cellR - .getCTR().getRPr() : cellR.getCTR().addNewRPr(); - CTFonts cellFonts = cellRpr.isSetRFonts() ? cellRpr - .getRFonts() : cellRpr.addNewRFonts(); - cellFonts.setAscii(tmpFonts.getAscii()); - cellFonts.setAsciiTheme(tmpFonts.getAsciiTheme()); - cellFonts.setCs(tmpFonts.getCs()); - cellFonts.setCstheme(tmpFonts.getCstheme()); - cellFonts.setEastAsia(tmpFonts.getEastAsia()); - cellFonts.setEastAsiaTheme(tmpFonts.getEastAsiaTheme()); - cellFonts.setHAnsi(tmpFonts.getHAnsi()); - cellFonts.setHAnsiTheme(tmpFonts.getHAnsiTheme()); - } - } - } - - } + copyFontInfo(cellR, tmpR); // 澶嶅埗娈佃惤淇℃伅 cellP.setAlignment(tmpP.getAlignment()); @@ -240,75 +219,128 @@ cellP.setBorderRight(tmpP.getBorderRight()); cellP.setBorderTop(tmpP.getBorderTop()); cellP.setPageBreak(tmpP.isPageBreak()); - if (tmpP.getCTP() != null) { - if (tmpP.getCTP().getPPr() != null) { - CTPPr tmpPpr = tmpP.getCTP().getPPr(); - CTPPr cellPpr = cellP.getCTP().getPPr() != null ? cellP.getCTP().getPPr() : cellP.getCTP().addNewPPr(); - // 澶嶅埗娈佃惤闂磋窛淇℃伅 - CTSpacing tmpSpacing = tmpPpr.getSpacing(); - if (tmpSpacing != null) { - CTSpacing cellSpacing = cellPpr.getSpacing() != null ? cellPpr - .getSpacing() : cellPpr.addNewSpacing(); - if (tmpSpacing.getAfter() != null) { - cellSpacing.setAfter(tmpSpacing.getAfter()); - } - if (tmpSpacing.getAfterAutospacing() != null) { - cellSpacing.setAfterAutospacing(tmpSpacing - .getAfterAutospacing()); - } - if (tmpSpacing.getAfterLines() != null) { - cellSpacing.setAfterLines(tmpSpacing.getAfterLines()); - } - if (tmpSpacing.getBefore() != null) { - cellSpacing.setBefore(tmpSpacing.getBefore()); - } - if (tmpSpacing.getBeforeAutospacing() != null) { - cellSpacing.setBeforeAutospacing(tmpSpacing - .getBeforeAutospacing()); - } - if (tmpSpacing.getBeforeLines() != null) { - cellSpacing.setBeforeLines(tmpSpacing.getBeforeLines()); - } - if (tmpSpacing.getLine() != null) { - cellSpacing.setLine(tmpSpacing.getLine()); - } - if (tmpSpacing.getLineRule() != null) { - cellSpacing.setLineRule(tmpSpacing.getLineRule()); - } - } + if (tmpP.getCTP() != null&&tmpP.getCTP().getPPr() != null) { + CTPPr tmpPpr = tmpP.getCTP().getPPr(); + CTPPr cellPpr = cellP.getCTP().getPPr() != null ? cellP.getCTP().getPPr() : cellP.getCTP().addNewPPr(); - // 澶嶅埗娈佃惤缂╄繘淇℃伅 - CTInd tmpInd = tmpPpr.getInd(); - if (tmpInd != null) { - CTInd cellInd = cellPpr.getInd() != null ? cellPpr.getInd() - : cellPpr.addNewInd(); - if (tmpInd.getFirstLine() != null) { - cellInd.setFirstLine(tmpInd.getFirstLine()); - } - if (tmpInd.getFirstLineChars() != null) { - cellInd.setFirstLineChars(tmpInd.getFirstLineChars()); - } - if (tmpInd.getHanging() != null) { - cellInd.setHanging(tmpInd.getHanging()); - } - if (tmpInd.getHangingChars() != null) { - cellInd.setHangingChars(tmpInd.getHangingChars()); - } - if (tmpInd.getLeft() != null) { - cellInd.setLeft(tmpInd.getLeft()); - } - if (tmpInd.getLeftChars() != null) { - cellInd.setLeftChars(tmpInd.getLeftChars()); - } - if (tmpInd.getRight() != null) { - cellInd.setRight(tmpInd.getRight()); - } - if (tmpInd.getRightChars() != null) { - cellInd.setRightChars(tmpInd.getRightChars()); - } + // 澶嶅埗娈佃惤闂磋窛淇℃伅 + copySpacing(tmpPpr, cellPpr); + + // 澶嶅埗娈佃惤缂╄繘淇℃伅 + copyParagraph(tmpPpr, cellPpr); + } + } + + /** + * 澶嶅埗瀛椾綋淇℃伅 + */ + private static void copyFontInfo(XWPFRun cellR, XWPFRun tmpR) { + if (tmpR == null) { + return; + } + if (!cellR.isBold()) { + cellR.setBold(tmpR.isBold()); + } + cellR.setItalic(tmpR.isItalic()); + cellR.setUnderline(tmpR.getUnderline()); + cellR.setColor(tmpR.getColor()); + cellR.setTextPosition(tmpR.getTextPosition()); + if (tmpR.getFontSize() != -1) { + cellR.setFontSize(tmpR.getFontSize()); + } + if (tmpR.getFontFamily() != null) { + cellR.setFontFamily(tmpR.getFontFamily()); + } + if (tmpR.getCTR() != null) { + if (tmpR.getCTR().isSetRPr()) { + CTRPr tmpRpr = tmpR.getCTR().getRPr(); + if (tmpRpr.isSetRFonts()) { + CTFonts tmpFonts = tmpRpr.getRFonts(); + CTRPr cellRpr = cellR.getCTR().isSetRPr() ? cellR + .getCTR().getRPr() : cellR.getCTR().addNewRPr(); + CTFonts cellFonts = cellRpr.isSetRFonts() ? cellRpr + .getRFonts() : cellRpr.addNewRFonts(); + cellFonts.setAscii(tmpFonts.getAscii()); + cellFonts.setAsciiTheme(tmpFonts.getAsciiTheme()); + cellFonts.setCs(tmpFonts.getCs()); + cellFonts.setCstheme(tmpFonts.getCstheme()); + cellFonts.setEastAsia(tmpFonts.getEastAsia()); + cellFonts.setEastAsiaTheme(tmpFonts.getEastAsiaTheme()); + cellFonts.setHAnsi(tmpFonts.getHAnsi()); + cellFonts.setHAnsiTheme(tmpFonts.getHAnsiTheme()); } } } } + + /** + * 澶嶅埗娈佃惤闂磋窛淇℃伅 + */ + private static void copySpacing(CTPPr tmpPpr, CTPPr cellPpr) { + CTSpacing tmpSpacing = tmpPpr.getSpacing(); + if (tmpSpacing != null) { + CTSpacing cellSpacing = cellPpr.getSpacing() != null ? cellPpr.getSpacing() : cellPpr.addNewSpacing(); + if (tmpSpacing.getAfter() != null) { + cellSpacing.setAfter(tmpSpacing.getAfter()); + } + if (tmpSpacing.getAfterAutospacing() != null) { + cellSpacing.setAfterAutospacing(tmpSpacing + .getAfterAutospacing()); + } + if (tmpSpacing.getAfterLines() != null) { + cellSpacing.setAfterLines(tmpSpacing.getAfterLines()); + } + if (tmpSpacing.getBefore() != null) { + cellSpacing.setBefore(tmpSpacing.getBefore()); + } + if (tmpSpacing.getBeforeAutospacing() != null) { + cellSpacing.setBeforeAutospacing(tmpSpacing + .getBeforeAutospacing()); + } + if (tmpSpacing.getBeforeLines() != null) { + cellSpacing.setBeforeLines(tmpSpacing.getBeforeLines()); + } + if (tmpSpacing.getLine() != null) { + cellSpacing.setLine(tmpSpacing.getLine()); + } + if (tmpSpacing.getLineRule() != null) { + cellSpacing.setLineRule(tmpSpacing.getLineRule()); + } + } + } + + /** + * 澶嶅埗娈佃惤缂╄繘淇℃伅 + */ + private static void copyParagraph(CTPPr tmpPpr, CTPPr cellPpr) { + CTInd tmpInd = tmpPpr.getInd(); + if (tmpInd != null) { + CTInd cellInd = cellPpr.getInd() != null ? cellPpr.getInd() : cellPpr.addNewInd(); + if (tmpInd.getFirstLine() != null) { + cellInd.setFirstLine(tmpInd.getFirstLine()); + } + if (tmpInd.getFirstLineChars() != null) { + cellInd.setFirstLineChars(tmpInd.getFirstLineChars()); + } + if (tmpInd.getHanging() != null) { + cellInd.setHanging(tmpInd.getHanging()); + } + if (tmpInd.getHangingChars() != null) { + cellInd.setHangingChars(tmpInd.getHangingChars()); + } + if (tmpInd.getLeft() != null) { + cellInd.setLeft(tmpInd.getLeft()); + } + if (tmpInd.getLeftChars() != null) { + cellInd.setLeftChars(tmpInd.getLeftChars()); + } + if (tmpInd.getRight() != null) { + cellInd.setRight(tmpInd.getRight()); + } + if (tmpInd.getRightChars() != null) { + cellInd.setRightChars(tmpInd.getRightChars()); + } + } + } } -- Gitblit v1.9.3