Search in sources :

Example 11 with XWPFTableRow

use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.

the class WordHelper method fillDecTeachExpData.

private XWPFTable fillDecTeachExpData(XWPFTable table, List<DecTeachExp> decTeachExps) {
    if (CollectionUtil.isEmpty(decTeachExps)) {
        return table;
    }
    if (decTeachExps.size() > 1) {
        int height = table.getRow(1).getHeight();
        for (int i = 1; i < decTeachExps.size(); i++) {
            table.createRow().setHeight(height);
        }
    }
    List<XWPFTableRow> rows = table.getRows();
    List<XWPFTableCell> cells;
    int rowCount = 1;
    for (DecTeachExp decTeachExp : decTeachExps) {
        cells = rows.get(rowCount).getTableCells();
        String dateBegin = decTeachExp.getDateBegin();
        if (StringUtil.isEmpty(dateBegin)) {
            dateBegin = "未知";
        }
        String dateEnd = decTeachExp.getDateEnd();
        if (StringUtil.isEmpty(dateEnd)) {
            dateEnd = "至今";
        }
        String value = dateBegin.concat("~").concat(dateEnd);
        cells.get(0).setText(value);
        value = decTeachExp.getSchoolName();
        if (StringUtil.notEmpty(value)) {
            cells.get(1).setText(value);
        }
        value = decTeachExp.getSubject();
        if (StringUtil.notEmpty(value)) {
            cells.get(2).setText(value);
        }
        value = decTeachExp.getNote();
        if (StringUtil.notEmpty(value)) {
            cells.get(3).setText(value);
        }
        for (XWPFTableCell cell : cells) {
            cell.setVerticalAlignment(XWPFVertAlign.CENTER);
        }
        rowCount++;
    }
    return table;
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) DecTeachExp(com.bc.pmpheep.back.po.DecTeachExp) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow)

Example 12 with XWPFTableRow

use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.

the class WordHelper method insertXWPFParagraph.

public static void insertXWPFParagraph(String key, XWPFDocument doc2, XWPFTable xwpfTable) {
    List<XWPFParagraph> paragraphList = doc2.getParagraphs();
    if (paragraphList != null && paragraphList.size() > 0) {
        for (int i = 0; i < paragraphList.size(); i++) {
            List<XWPFRun> runs = paragraphList.get(i).getRuns();
            for (XWPFRun run : runs) {
                String text = run.getText(0);
                if (text != null) {
                    if (text.equals(key)) {
                        XmlCursor cursor = paragraphList.get(i + 1).getCTP().newCursor();
                        XWPFTable table = doc2.insertNewTbl(cursor);
                        XWPFTableRow tableRow = table.getRow(0);
                        for (int cellNum = 0; cellNum < 27; cellNum++) {
                            tableRow.addNewTableCell();
                        }
                        for (int rowNum = 0; rowNum < 3; rowNum++) {
                            table.createRow();
                        }
                        // 合并列(没有作用)
                        for (int rowNum = 0; rowNum < table.getRows().size(); rowNum++) {
                            for (int cellIndex = 0; cellIndex < tableRow.getTableCells().size(); cellIndex++) {
                                CTHMerge hmerge = CTHMerge.Factory.newInstance();
                                if (cellIndex == 0) {
                                    // The first merged cell is set with RESTART merge value
                                    hmerge.setVal(STMerge.RESTART);
                                } else {
                                    // Cells which join (merge) the first one, are set with CONTINUE
                                    hmerge.setVal(STMerge.CONTINUE);
                                }
                                XWPFTableCell cell = table.getRow(rowNum).getCell(cellIndex);
                                // Try getting the TcPr. Not simply setting an new one every time.
                                CTTcPr tcPr = cell.getCTTc().getTcPr();
                                if (tcPr != null) {
                                    tcPr.setHMerge(hmerge);
                                } else {
                                    // only set an new TcPr if there is not one already
                                    tcPr = CTTcPr.Factory.newInstance();
                                    tcPr.setHMerge(hmerge);
                                    cell.getCTTc().setTcPr(tcPr);
                                }
                            }
                        }
                        // 合并行
                        for (int col = 0; col < tableRow.getTableCells().size(); col++) {
                            for (int rowIndex = 0; rowIndex < table.getRows().size(); rowIndex++) {
                                XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
                                if (rowIndex == 0) {
                                    // The first merged cell is set with RESTART merge value
                                    cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
                                } else {
                                    // Cells which join (merge) the first one, are set with CONTINUE
                                    cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) XWPFTable(org.apache.poi.xwpf.usermodel.XWPFTable) XmlCursor(org.apache.xmlbeans.XmlCursor) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow)

Example 13 with XWPFTableRow

use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.

the class WordHelper method addTable.

public XWPFDocument addTable(XWPFDocument document) {
    List<XWPFTable> tables = document.getTables();
    XWPFTable old = tables.get(19);
    XWPFTable t = document.createTable();
    XWPFTableRow row = t.getRow(0);
    XWPFTableCell cell = row.getCell(0);
    CTTc cttc = cell.getCTTc();
    CTTcPr tcpr = cttc.addNewTcPr();
    CTTblWidth tcw = tcpr.addNewTcW();
    tcw.setType(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getType());
    tcw.setW(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getW());
    if (old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan() != null) {
        tcpr.setGridSpan(old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan());
    }
    XWPFRun run = cell.getParagraphs().get(0).createRun();
    run.setText("Cells which join (merge) the first one, are set with CONTINUE");
    return document;
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) XWPFTable(org.apache.poi.xwpf.usermodel.XWPFTable) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow)

Example 14 with XWPFTableRow

use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.

the class WordHelper method fillDecResearchData.

private XWPFTable fillDecResearchData(XWPFTable table, List<DecResearch> decResearchs) {
    if (CollectionUtil.isEmpty(decResearchs)) {
        return table;
    }
    if (decResearchs.size() > 1) {
        int height = table.getRow(1).getHeight();
        for (int i = 1; i < decResearchs.size(); i++) {
            table.createRow().setHeight(height);
        }
    }
    List<XWPFTableRow> rows = table.getRows();
    List<XWPFTableCell> cells;
    int rowCount = 1;
    for (DecResearch decResearch : decResearchs) {
        cells = rows.get(rowCount).getTableCells();
        String value = decResearch.getResearchName();
        if (StringUtil.notEmpty(value)) {
            cells.get(0).setText(value);
        }
        value = decResearch.getApprovalUnit();
        if (StringUtil.notEmpty(value)) {
            cells.get(1).setText(value);
        }
        value = decResearch.getAward();
        if (StringUtil.notEmpty(value)) {
            cells.get(2).setText(value);
        }
        value = decResearch.getNote();
        if (StringUtil.notEmpty(value)) {
            cells.get(3).setText(value);
        }
        for (XWPFTableCell cell : cells) {
            cell.setVerticalAlignment(XWPFVertAlign.CENTER);
        }
        rowCount++;
    }
    return table;
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) DecResearch(com.bc.pmpheep.back.po.DecResearch) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow)

Example 15 with XWPFTableRow

use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.

the class WordHelper method fillDecEduExpData.

private XWPFTable fillDecEduExpData(XWPFTable table, List<DecEduExp> decEduExps) {
    if (CollectionUtil.isEmpty(decEduExps)) {
        return table;
    }
    if (decEduExps.size() > 1) {
        int height = table.getRow(1).getHeight();
        for (int i = 1; i < decEduExps.size(); i++) {
            table.createRow().setHeight(height);
        }
    }
    List<XWPFTableRow> rows = table.getRows();
    List<XWPFTableCell> cells;
    int rowCount = 1;
    for (DecEduExp decEduExp : decEduExps) {
        cells = rows.get(rowCount).getTableCells();
        String dateBegin = decEduExp.getDateBegin();
        if (StringUtil.isEmpty(dateBegin)) {
            dateBegin = "未知";
        }
        String dateEnd = decEduExp.getDateEnd();
        if (StringUtil.isEmpty(dateEnd)) {
            dateEnd = "至今";
        }
        String value = dateBegin.concat("~").concat(dateEnd);
        cells.get(0).setText(value);
        value = decEduExp.getSchoolName();
        if (StringUtil.notEmpty(value)) {
            cells.get(1).setText(value);
        }
        value = decEduExp.getMajor();
        if (StringUtil.notEmpty(value)) {
            cells.get(2).setText(value);
        }
        value = decEduExp.getDegree();
        if (StringUtil.notEmpty(value)) {
            cells.get(3).setText(value);
        }
        value = decEduExp.getNote();
        if (StringUtil.notEmpty(value)) {
            cells.get(4).setText(value);
        }
        for (XWPFTableCell cell : cells) {
            cell.setVerticalAlignment(XWPFVertAlign.CENTER);
        }
        rowCount++;
    }
    return table;
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) DecEduExp(com.bc.pmpheep.back.po.DecEduExp) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow)

Aggregations

XWPFTableRow (org.apache.poi.xwpf.usermodel.XWPFTableRow)27 XWPFTableCell (org.apache.poi.xwpf.usermodel.XWPFTableCell)26 BigInteger (java.math.BigInteger)9 Date (java.util.Date)8 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)6 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)5 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)5 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 CTTblPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr)3 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ICell (org.apache.poi.xwpf.usermodel.ICell)2 XWPFSDTCell (org.apache.poi.xwpf.usermodel.XWPFSDTCell)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 CTDecimalNumber (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber)2 CTHeight (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight)2 CTShd (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd)2 CTString (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString)2 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)2 DeclarationEtcBO (com.bc.pmpheep.back.bo.DeclarationEtcBO)1