Search in sources :

Example 6 with CTP

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

the class TestXWPFParagraph method testSetGetSpacing.

@Test
public void testSetGetSpacing() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    assertEquals(-1, p.getSpacingBefore());
    assertEquals(-1, p.getSpacingAfter());
    assertEquals(-1, p.getSpacingBetween(), 0.1);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    CTSpacing spacing = ppr.addNewSpacing();
    spacing.setAfter(new BigInteger("10"));
    assertEquals(10, p.getSpacingAfter());
    spacing.setBefore(new BigInteger("10"));
    assertEquals(10, p.getSpacingBefore());
    p.setSpacingAfter(100);
    assertEquals(100, spacing.getAfter().intValue());
    p.setSpacingBefore(100);
    assertEquals(100, spacing.getBefore().intValue());
    p.setSpacingBetween(.25, LineSpacingRule.EXACT);
    assertEquals(.25, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.EXACT, p.getSpacingLineRule());
    p.setSpacingBetween(1.25, LineSpacingRule.AUTO);
    assertEquals(1.25, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    p.setSpacingBetween(.5, LineSpacingRule.AT_LEAST);
    assertEquals(.5, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
    p.setSpacingBetween(1.15);
    assertEquals(1.15, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTSpacing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing) BigInteger(java.math.BigInteger) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 7 with CTP

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

the class TestXWPFParagraph method testSetGetPageBreak.

@Test
public void testSetGetPageBreak() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    CTOnOff pageBreak = ppr.addNewPageBreakBefore();
    pageBreak.setVal(STOnOff.FALSE);
    assertEquals(false, p.isPageBreak());
    p.setPageBreak(true);
    assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTOnOff(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 8 with CTP

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

the class TestXWPFParagraph method testSetGetIndentation.

@Test
public void testSetGetIndentation() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    assertEquals(-1, p.getIndentationLeft());
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    assertEquals(-1, p.getIndentationLeft());
    CTInd ind = ppr.addNewInd();
    ind.setLeft(new BigInteger("10"));
    assertEquals(10, p.getIndentationLeft());
    p.setIndentationLeft(100);
    assertEquals(100, ind.getLeft().intValue());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTInd(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd) BigInteger(java.math.BigInteger) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 9 with CTP

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

the class XWPFHeaderFooter method insertNewParagraph.

/**
     * add a new paragraph at position of the cursor
     *
     * @param cursor
     * @return the inserted paragraph
     */
public XWPFParagraph insertNewParagraph(XmlCursor cursor) {
    if (isCursorInHdrF(cursor)) {
        String uri = CTP.type.getName().getNamespaceURI();
        String localPart = "p";
        cursor.beginElement(localPart, uri);
        cursor.toParent();
        CTP p = (CTP) cursor.getObject();
        XWPFParagraph newP = new XWPFParagraph(p, this);
        XmlObject o = null;
        while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
            o = cursor.getObject();
        }
        if ((!(o instanceof CTP)) || (CTP) o == p) {
            paragraphs.add(0, newP);
        } else {
            int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
            paragraphs.add(pos, newP);
        }
        int i = 0;
        XmlCursor p2 = p.newCursor();
        cursor.toCursor(p2);
        p2.dispose();
        while (cursor.toPrevSibling()) {
            o = cursor.getObject();
            if (o instanceof CTP || o instanceof CTTbl)
                i++;
        }
        bodyElements.add(i, newP);
        p2 = p.newCursor();
        cursor.toCursor(p2);
        cursor.toEndToken();
        p2.dispose();
        return newP;
    }
    return null;
}
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)

Example 10 with CTP

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

the class XWPFHeaderFooter method insertNewTbl.

/**
     * @param cursor
     * @return the inserted table
     */
public XWPFTable insertNewTbl(final XmlCursor cursor) {
    if (isCursorInHdrF(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;
        XmlCursor cursor2 = t.newCursor();
        while (cursor2.toPrevSibling()) {
            o = cursor2.getObject();
            if (o instanceof CTP || o instanceof CTTbl) {
                i++;
            }
        }
        cursor2.dispose();
        bodyElements.add(i, newT);
        cursor2 = t.newCursor();
        cursor.toCursor(cursor2);
        cursor.toEndToken();
        cursor2.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)

Aggregations

CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)28 XmlCursor (org.apache.xmlbeans.XmlCursor)12 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)11 XmlObject (org.apache.xmlbeans.XmlObject)10 Test (org.junit.Test)10 CTPPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr)10 CTR (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR)4 CTText (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText)4 BigInteger (java.math.BigInteger)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 POIXMLException (org.apache.poi.POIXMLException)2 XWPFHeaderFooterPolicy (org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy)2 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)2 CTOnOff (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff)2 CTSpacing (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing)2 CTLock (com.microsoft.schemas.office.office.CTLock)1 CTFormulas (com.microsoft.schemas.vml.CTFormulas)1 CTGroup (com.microsoft.schemas.vml.CTGroup)1