管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-10 9b6fc58ae37b2745310e6942af1a4dae51a82c56
1
已修改1个文件
67 ■■■■■ 文件已修改
src/main/java/com/lf/server/helper/WordHelper.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/WordHelper.java
@@ -20,9 +20,12 @@
     * 通过word模板生成word的主方法
     */
    public static void generateWord(String inputFile, String outPutFile, Map<String, String> insertTextMap, List<String[]> addList) {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        try {
            FileInputStream inputStream = new FileInputStream(inputFile);
            FileOutputStream outputStream = new FileOutputStream(outPutFile);
            inputStream = new FileInputStream(inputFile);
            outputStream = new FileOutputStream(outPutFile);
            // 获取docx解析对象
            XWPFDocument xwpfDocument = new XWPFDocument(inputStream);
@@ -37,11 +40,19 @@
            // 写入数据
            xwpfDocument.write(outputStream);
            outputStream.close();
            inputStream.close();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
@@ -107,23 +118,25 @@
     * 插入数据
     */
    private static void insertData(XWPFTable table, List<String[]> addList) {
        XWPFTableRow oldRow = table.getRow(1);
        for (int i = 1; i < addList.size(); i++) {
        for (int i = 1, c = addList.size(); i < c; i++) {
            XWPFTableRow row = table.createRow();
            row.setHeight(oldRow.getHeight());
        }
        List<XWPFTableCell> oldCells = table.getRow(1).getTableCells();
        List<XWPFTableRow> rowList = table.getRows();
        for (int i = 1; i < rowList.size(); i++) {
            XWPFTableRow xwpfTableRow = rowList.get(i);
        for (int i = 0, c = addList.size(); i < c; i++) {
            XWPFTableRow xwpfTableRow = rowList.get(i + 1);
            List<XWPFTableCell> tableCells = xwpfTableRow.getTableCells();
            for (int j = 0; j < tableCells.size(); j++) {
                XWPFTableCell oldCell = oldRow.getTableCells().get(j);
                XWPFTableCell oldCell = oldCells.get(j);
                XWPFTableCell newCell = tableCells.get(j);
                //newCell.setText(addList.get(i - 1)[j]);
                setCellText(oldCell, newCell, addList.get(i - 1)[j]);
                if (0 == i) {
                    newCell.setText(addList.get(i)[j]);
                } else {
                    setCellText(oldCell, newCell, addList.get(i)[j]);
                }
            }
        }
    }
@@ -197,13 +210,13 @@
            }
            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
                    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();
                        CTFonts cellFonts = cellRpr.isSetRFonts() ? cellRpr
                                .getRFonts() : cellRpr.addNewRFonts();
                        cellFonts.setAscii(tmpFonts.getAscii());
                        cellFonts.setAsciiTheme(tmpFonts.getAsciiTheme());
                        cellFonts.setCs(tmpFonts.getCs());
@@ -229,14 +242,14 @@
        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();
                CTPPr tmpPpr = tmpP.getCTP().getPPr();
                CTPPr cellPpr = cellP.getCTP().getPPr() != null ? cellP.getCTP().getPPr() : cellP.getCTP().addNewPPr();
                // 复制段落间距信息
                CTSpacing tmpSpacing = tmpPPr.getSpacing();
                CTSpacing tmpSpacing = tmpPpr.getSpacing();
                if (tmpSpacing != null) {
                    CTSpacing cellSpacing = cellPPr.getSpacing() != null ? cellPPr
                            .getSpacing() : cellPPr.addNewSpacing();
                    CTSpacing cellSpacing = cellPpr.getSpacing() != null ? cellPpr
                            .getSpacing() : cellPpr.addNewSpacing();
                    if (tmpSpacing.getAfter() != null) {
                        cellSpacing.setAfter(tmpSpacing.getAfter());
                    }
@@ -266,10 +279,10 @@
                }
                // 复制段落缩进信息
                CTInd tmpInd = tmpPPr.getInd();
                CTInd tmpInd = tmpPpr.getInd();
                if (tmpInd != null) {
                    CTInd cellInd = cellPPr.getInd() != null ? cellPPr.getInd()
                            : cellPPr.addNewInd();
                    CTInd cellInd = cellPpr.getInd() != null ? cellPpr.getInd()
                            : cellPpr.addNewInd();
                    if (tmpInd.getFirstLine() != null) {
                        cellInd.setFirstLine(tmpInd.getFirstLine());
                    }