Search in sources :

Example 1 with SdtRun

use of org.docx4j.wml.SdtRun in project docx4j-template by vindell.

the class SdtFinder method printSdtContent.

public void printSdtContent(String filePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(filePath));
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    Document wmlDocumentEl = (Document) mdp.getContents();
    Body body = wmlDocumentEl.getBody();
    SdtFinder sdtFinder = new SdtFinder();
    new TraversalUtil(body, sdtFinder);
    for (Child sdtChild : sdtFinder.sdtList) {
        if (sdtChild instanceof SdtRun) {
            SdtRun sdtRun = (SdtRun) sdtChild;
            SdtPr sdtPr = sdtRun.getSdtPr();
            printSdtPrContent(sdtPr);
            // System.out.println(XmlUtils.marshaltoString(sdtPr, true,
            // true));
            SdtContent sdtContent = sdtRun.getSdtContent();
            System.out.println("-----------p content=" + getContentAccessorContent(sdtContent));
        } else if (sdtChild instanceof CTSdtCell) {
            CTSdtCell sdtCell = (CTSdtCell) sdtChild;
            SdtPr sdtPr = sdtCell.getSdtPr();
            printSdtPrContent(sdtPr);
            SdtContent sdtContent = sdtCell.getSdtContent();
            System.out.println("-----------table content=" + getContentAccessorContent(sdtContent));
        } else if (sdtChild instanceof SdtBlock) {
            SdtBlock sdtBlock = (SdtBlock) sdtChild;
            SdtPr sdtPr = sdtBlock.getSdtPr();
            printSdtPrContent(sdtPr);
            SdtContent sdtContent = sdtBlock.getSdtContent();
            System.out.println("-----------sdtblock content=" + getContentAccessorContent(sdtContent));
        }
    }
}
Also used : SdtPr(org.docx4j.wml.SdtPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Document(org.docx4j.wml.Document) CTSdtCell(org.docx4j.wml.CTSdtCell) TraversalUtil(org.docx4j.TraversalUtil) SdtRun(org.docx4j.wml.SdtRun) SdtContent(org.docx4j.wml.SdtContent) File(java.io.File) Body(org.docx4j.wml.Body) Child(org.jvnet.jaxb2_commons.ppp.Child) SdtBlock(org.docx4j.wml.SdtBlock)

Example 2 with SdtRun

use of org.docx4j.wml.SdtRun in project docx4j-template by vindell.

the class SdtFinder_2 method printSdtContent.

public void printSdtContent(String filePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(filePath));
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    Document wmlDocumentEl = (Document) mdp.getContents();
    Body body = wmlDocumentEl.getBody();
    SdtFinder_2 sdtFinder = new SdtFinder_2();
    new TraversalUtil(body, sdtFinder);
    for (Child sdtChild : sdtFinder.sdtList) {
        if (sdtChild instanceof SdtRun) {
            SdtRun sdtRun = (SdtRun) sdtChild;
            SdtPr sdtPr = sdtRun.getSdtPr();
            printSdtPrContent(sdtPr);
            SdtContent sdtContent = sdtRun.getSdtContent();
            System.out.println("-----------p content=" + getSdtContentContent(sdtContent));
        } else if (sdtChild instanceof CTSdtCell) {
            CTSdtCell sdtCell = (CTSdtCell) sdtChild;
            SdtPr sdtPr = sdtCell.getSdtPr();
            printSdtPrContent(sdtPr);
            SdtContent sdtContent = sdtCell.getSdtContent();
            System.out.println("-----------table content=" + getSdtContentContent(sdtContent));
        } else if (sdtChild instanceof SdtBlock) {
            SdtBlock sdtBlock = (SdtBlock) sdtChild;
            SdtPr sdtPr = sdtBlock.getSdtPr();
            printSdtPrContent(sdtPr);
            SdtContent sdtContent = sdtBlock.getSdtContent();
            System.out.println("-----------sdtblock content=" + getSdtContentContent(sdtContent));
        }
    }
}
Also used : SdtPr(org.docx4j.wml.SdtPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Document(org.docx4j.wml.Document) CTSdtCell(org.docx4j.wml.CTSdtCell) TraversalUtil(org.docx4j.TraversalUtil) SdtRun(org.docx4j.wml.SdtRun) SdtContent(org.docx4j.wml.SdtContent) File(java.io.File) Body(org.docx4j.wml.Body) Child(org.jvnet.jaxb2_commons.ppp.Child) SdtBlock(org.docx4j.wml.SdtBlock)

Aggregations

File (java.io.File)2 TraversalUtil (org.docx4j.TraversalUtil)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)2 Body (org.docx4j.wml.Body)2 CTSdtCell (org.docx4j.wml.CTSdtCell)2 Document (org.docx4j.wml.Document)2 SdtBlock (org.docx4j.wml.SdtBlock)2 SdtContent (org.docx4j.wml.SdtContent)2 SdtPr (org.docx4j.wml.SdtPr)2 SdtRun (org.docx4j.wml.SdtRun)2 Child (org.jvnet.jaxb2_commons.ppp.Child)2