Search in sources :

Example 6 with CTTc

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

the class TestXWPFTable method testGetText.

public void testGetText() {
    XWPFDocument doc = new XWPFDocument();
    CTTbl table = CTTbl.Factory.newInstance();
    CTRow row = table.addNewTr();
    CTTc cell = row.addNewTc();
    CTP paragraph = cell.addNewP();
    CTR run = paragraph.addNewR();
    CTText text = run.addNewT();
    text.setStringValue("finally I can write!");
    XWPFTable xtab = new XWPFTable(table, doc);
    assertEquals("finally I can write!\n", xtab.getText());
}
Also used : CTR(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR) CTText(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)

Example 7 with CTTc

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

the class XWPFTableRow method getTableICells.

/**
     * create and return a list of all XWPFTableCell
     * who belongs to this row
     *
     * @return a list of {@link XWPFTableCell}
     */
public List<ICell> getTableICells() {
    List<ICell> cells = new ArrayList<ICell>();
    //Can't use ctRow.getTcList because that only gets table cells
    //Can't use ctRow.getSdtList because that only gets sdts that are at cell level
    XmlCursor cursor = ctRow.newCursor();
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
        XmlObject o = cursor.getObject();
        if (o instanceof CTTc) {
            cells.add(new XWPFTableCell((CTTc) o, this, table.getBody()));
        } else if (o instanceof CTSdtCell) {
            cells.add(new XWPFSDTCell((CTSdtCell) o, this, table.getBody()));
        }
    }
    cursor.dispose();
    return cells;
}
Also used : ArrayList(java.util.ArrayList) XmlObject(org.apache.xmlbeans.XmlObject) CTSdtCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtCell) XmlCursor(org.apache.xmlbeans.XmlCursor) CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)

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