| | |
| | | */ |
| | | 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(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | cellR.setText(text); |
| | | |
| | | // 复制字体信息 |
| | | if (tmpR != null) { |
| | | copyFontInfo(cellR, tmpR); |
| | | |
| | | // 复制段落信息 |
| | | cellP.setAlignment(tmpP.getAlignment()); |
| | | cellP.setVerticalAlignment(tmpP.getVerticalAlignment()); |
| | | cellP.setBorderBetween(tmpP.getBorderBetween()); |
| | | cellP.setBorderBottom(tmpP.getBorderBottom()); |
| | | cellP.setBorderLeft(tmpP.getBorderLeft()); |
| | | cellP.setBorderRight(tmpP.getBorderRight()); |
| | | cellP.setBorderTop(tmpP.getBorderTop()); |
| | | cellP.setPageBreak(tmpP.isPageBreak()); |
| | | |
| | | 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(); |
| | | |
| | | // 复制段落间距信息 |
| | | 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()); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 复制段落信息 |
| | | cellP.setAlignment(tmpP.getAlignment()); |
| | | cellP.setVerticalAlignment(tmpP.getVerticalAlignment()); |
| | | cellP.setBorderBetween(tmpP.getBorderBetween()); |
| | | cellP.setBorderBottom(tmpP.getBorderBottom()); |
| | | cellP.setBorderLeft(tmpP.getBorderLeft()); |
| | | 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(); |
| | | |
| | | // 复制段落间距信息 |
| | | /** |
| | | * 复制段落间距信息 |
| | | */ |
| | | private static void copySpacing(CTPPr tmpPpr, CTPPr cellPpr) { |
| | | 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()); |
| | | } |
| | |
| | | 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(); |
| | | CTInd cellInd = cellPpr.getInd() != null ? cellPpr.getInd() : cellPpr.addNewInd(); |
| | | if (tmpInd.getFirstLine() != null) { |
| | | cellInd.setFirstLine(tmpInd.getFirstLine()); |
| | | } |
| | |
| | | } |
| | | if (tmpInd.getRightChars() != null) { |
| | | cellInd.setRightChars(tmpInd.getRightChars()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |