Search in sources :

Example 21 with CTTbl

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

the class XWPFFootnote method insertNewTbl.

/**
     * @param cursor
     * @return the inserted table
     * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
     */
public XWPFTable insertNewTbl(XmlCursor cursor) {
    if (isCursorInFtn(cursor)) {
        String uri = CTTbl.type.getName().getNamespaceURI();
        String localPart = "tbl";
        cursor.beginElement(localPart, uri);
        cursor.toParent();
        CTTbl t = (CTTbl) cursor.getObject();
        XWPFTable newT = new XWPFTable(t, this);
        cursor.removeXmlContents();
        XmlObject o = null;
        while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
            o = cursor.getObject();
        }
        if (!(o instanceof CTTbl)) {
            tables.add(0, newT);
        } else {
            int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
            tables.add(pos, newT);
        }
        int i = 0;
        cursor = t.newCursor();
        while (cursor.toPrevSibling()) {
            o = cursor.getObject();
            if (o instanceof CTP || o instanceof CTTbl)
                i++;
        }
        bodyElements.add(i, newT);
        XmlCursor c2 = t.newCursor();
        cursor.toCursor(c2);
        cursor.toEndToken();
        c2.dispose();
        return newT;
    }
    return null;
}
Also used : CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) XmlObject(org.apache.xmlbeans.XmlObject) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 22 with CTTbl

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

the class XWPFFootnote method init.

private void init() {
    XmlCursor cursor = ctFtnEdn.newCursor();
    //copied from XWPFDocument...should centralize this code
    //to avoid duplication
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
        XmlObject o = cursor.getObject();
        if (o instanceof CTP) {
            XWPFParagraph p = new XWPFParagraph((CTP) o, this);
            bodyElements.add(p);
            paragraphs.add(p);
        } else if (o instanceof CTTbl) {
            XWPFTable t = new XWPFTable((CTTbl) o, this);
            bodyElements.add(t);
            tables.add(t);
        } else if (o instanceof CTSdtBlock) {
            XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
            bodyElements.add(c);
        }
    }
    cursor.dispose();
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 23 with CTTbl

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

the class XWPFHeader method onDocumentRead.

/**
     * reads the document
     *
     * @throws IOException
     */
@Override
protected void onDocumentRead() throws IOException {
    super.onDocumentRead();
    HdrDocument hdrDocument = null;
    InputStream is = null;
    try {
        is = getPackagePart().getInputStream();
        hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        headerFooter = hdrDocument.getHdr();
        // parse the document with cursor and add
        // the XmlObject to its lists
        XmlCursor cursor = headerFooter.newCursor();
        cursor.selectPath("./*");
        while (cursor.toNextSelection()) {
            XmlObject o = cursor.getObject();
            if (o instanceof CTP) {
                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                paragraphs.add(p);
                bodyElements.add(p);
            }
            if (o instanceof CTTbl) {
                XWPFTable t = new XWPFTable((CTTbl) o, this);
                tables.add(t);
                bodyElements.add(t);
            }
            if (o instanceof CTSdtBlock) {
                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
                bodyElements.add(c);
            }
        }
        cursor.dispose();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : HdrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) POIXMLException(org.apache.poi.POIXMLException) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 24 with CTTbl

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

the class TestXWPFTable method testSetGetHBorders.

public void testSetGetHBorders() {
    // instantiate the following classes so they'll get picked up by
    // the XmlBean process and added to the jar file. they are required
    // for the following XWPFTable methods.
    CTTblBorders cttb = CTTblBorders.Factory.newInstance();
    assertNotNull(cttb);
    STBorder stb = STBorder.Factory.newInstance();
    assertNotNull(stb);
    // create a table
    XWPFDocument doc = new XWPFDocument();
    CTTbl ctTable = CTTbl.Factory.newInstance();
    XWPFTable table = new XWPFTable(ctTable, doc);
    // set inside horizontal border
    table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
    // get inside horizontal border components
    int s = table.getInsideHBorderSize();
    assertEquals(4, s);
    int sp = table.getInsideHBorderSpace();
    assertEquals(0, sp);
    String clr = table.getInsideHBorderColor();
    assertEquals("FF0000", clr);
    XWPFBorderType bt = table.getInsideHBorderType();
    assertEquals(XWPFBorderType.SINGLE, bt);
}
Also used : XWPFBorderType(org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType) STBorder(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder) CTTblBorders(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Example 25 with CTTbl

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

the class TestXWPFTable method testSetGetWidth.

public void testSetGetWidth() {
    XWPFDocument doc = new XWPFDocument();
    CTTbl table = CTTbl.Factory.newInstance();
    table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
    XWPFTable xtab = new XWPFTable(table, doc);
    assertEquals(1000, xtab.getWidth());
    xtab.setWidth(100);
    assertEquals(100, table.getTblPr().getTblW().getW().intValue());
}
Also used : BigInteger(java.math.BigInteger) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Aggregations

CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)31 XmlCursor (org.apache.xmlbeans.XmlCursor)14 XmlObject (org.apache.xmlbeans.XmlObject)13 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)11 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)5 BigInteger (java.math.BigInteger)4 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3 CTTblPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr)3 InputStream (java.io.InputStream)2 POIXMLException (org.apache.poi.POIXMLException)2 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)2 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)2 XWPFBorderType (org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType)2 XWPFTableCell (org.apache.poi.xwpf.usermodel.XWPFTableCell)2 XWPFTableRow (org.apache.poi.xwpf.usermodel.XWPFTableRow)2 CTTblBorders (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders)2 CTTblGrid (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1