Search in sources :

Example 1 with CTTc

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc in project poi by apache.

the class XWPFFootnote method getTableCell.

/**
     * get the TableCell which belongs to the TableCell
     *
     * @param cell
     * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
     */
public XWPFTableCell getTableCell(CTTc cell) {
    XmlCursor cursor = cell.newCursor();
    cursor.toParent();
    XmlObject o = cursor.getObject();
    if (!(o instanceof CTRow)) {
        return null;
    }
    CTRow row = (CTRow) o;
    cursor.toParent();
    o = cursor.getObject();
    cursor.dispose();
    if (!(o instanceof CTTbl)) {
        return null;
    }
    CTTbl tbl = (CTTbl) o;
    XWPFTable table = getTable(tbl);
    if (table == null) {
        return null;
    }
    XWPFTableRow tableRow = table.getRow(row);
    if (tableRow == null) {
        return null;
    }
    return tableRow.getTableCell(cell);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 2 with CTTc

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc in project poi by apache.

the class XWPFHeaderFooter method getTableCell.

/**
     * get the TableCell which belongs to the TableCell
     *
     * @param cell
     */
public XWPFTableCell getTableCell(CTTc cell) {
    XmlCursor cursor = cell.newCursor();
    cursor.toParent();
    XmlObject o = cursor.getObject();
    if (!(o instanceof CTRow)) {
        cursor.dispose();
        return null;
    }
    CTRow row = (CTRow) o;
    cursor.toParent();
    o = cursor.getObject();
    cursor.dispose();
    if (!(o instanceof CTTbl)) {
        return null;
    }
    CTTbl tbl = (CTTbl) o;
    XWPFTable table = getTable(tbl);
    if (table == null) {
        return null;
    }
    XWPFTableRow tableRow = table.getRow(row);
    return tableRow.getTableCell(cell);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 3 with CTTc

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc in project poi by apache.

the class XWPFTableRow method addNewTableCell.

/**
     * adds a new TableCell at the end of this tableRow
     */
public XWPFTableCell addNewTableCell() {
    CTTc cell = ctRow.addNewTc();
    XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.getBody());
    tableCells.add(tableCell);
    return tableCell;
}
Also used : CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)

Example 4 with CTTc

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc in project poi by apache.

the class XWPFTableRow method getTableCells.

/**
     * create and return a list of all XWPFTableCell
     * who belongs to this row
     *
     * @return a list of {@link XWPFTableCell}
     */
public List<XWPFTableCell> getTableCells() {
    if (tableCells == null) {
        List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
        for (CTTc tableCell : ctRow.getTcArray()) {
            cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
        }
        //TODO: it is possible to have an SDT that contains a cell in within a row
        //need to modify this code so that it pulls out SDT wrappers around cells, too.
        this.tableCells = cells;
    }
    return tableCells;
}
Also used : ArrayList(java.util.ArrayList) CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)

Example 5 with CTTc

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc in project poi by apache.

the class XWPFTableCell method getTableCell.

/**
     * get the TableCell which belongs to the TableCell
     */
public XWPFTableCell getTableCell(CTTc cell) {
    XmlCursor cursor = cell.newCursor();
    cursor.toParent();
    XmlObject o = cursor.getObject();
    if (!(o instanceof CTRow)) {
        return null;
    }
    CTRow row = (CTRow) o;
    cursor.toParent();
    o = cursor.getObject();
    cursor.dispose();
    if (!(o instanceof CTTbl)) {
        return null;
    }
    CTTbl tbl = (CTTbl) o;
    XWPFTable table = getTable(tbl);
    if (table == null) {
        return null;
    }
    XWPFTableRow tr = table.getRow(row);
    if (tr == null) {
        return null;
    }
    return tr.getTableCell(cell);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlCursor (org.apache.xmlbeans.XmlCursor)4 XmlObject (org.apache.xmlbeans.XmlObject)4 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)4 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)4 CTTc (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)4 ArrayList (java.util.ArrayList)2 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)1 CTR (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR)1 CTSdtCell (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtCell)1 CTText (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText)1