Package org.docx4j.wml

Examples of org.docx4j.wml.ObjectFactory


    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement();
    Body body =  wmlDocumentEl.getBody();
   
        ObjectFactory factory = Context.getWmlObjectFactory();
       
        /* Create the following:
         *
        <w:p>
          <w:r>
            <w:fldChar w:dirty="true" w:fldCharType="begin"/>
            <w:instrText xml:space="preserve">TOC \o &quot;1-3&quot; \h \z \ u \h</w:instrText>
          </w:r>
          <w:r/>
          <w:r>
            <w:fldChar w:fldCharType="end"/>
          </w:r>
        </w:p>         */       
        P paragraphForTOC = factory.createP();          
        R r = factory.createR();

        FldChar fldchar = factory.createFldChar();
        fldchar.setFldCharType(STFldCharType.BEGIN);
        fldchar.setDirty(true);
        r.getContent().add(getWrappedFldChar(fldchar));
        paragraphForTOC.getContent().add(r);

        R r1 = factory.createR();
        Text txt = new Text();
        txt.setSpace("preserve");
        txt.setValue("TOC \\o \"1-3\" \\h \\z \\u \\h");
        r.getContent().add(factory.createRInstrText(txt) );
        paragraphForTOC.getContent().add(r1);

        FldChar fldcharend = factory.createFldChar();
        fldcharend.setFldCharType(STFldCharType.END);
        R r2 = factory.createR();
        r2.getContent().add(getWrappedFldChar(fldcharend));
        paragraphForTOC.getContent().add(r2);
           
    body.getContent().add(paragraphForTOC);
   
View Full Code Here


    System.out.println(row1.toString());
  }

  private CTSimpleField createSimpleField(SwitchTestQuad triple, String varname, boolean useVarname) {

    ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

    CTSimpleField field = wmlObjectFactory.createCTSimpleField();
    String instr = null;
    if (triple.format==null ) {
      if (useVarname && (instruction.equals("DOCPROPERTY ")
          || instruction.equals("MERGEFIELD "))) {
        instr = instruction + varname + " " + formattingSwitch;       
      } else {
        instr = instruction +triple.val + " " + formattingSwitch;
      }
    } else {
      if (useVarname && (instruction.equals("DOCPROPERTY ")
          || instruction.equals("MERGEFIELD "))) {
        if (triple.format.equals("")) {
          instr = instruction + varname  + " " + formattingSwitch;
        } else
        {
          instr = instruction + varname + " " + formattingSwitch + " " + triple.format;
        }
      } else {
        instr = instruction + triple.val + " " + formattingSwitch + " " + triple.format;
      }
    }

    field.setInstr(instr);

    R r = wmlObjectFactory.createR();
    Text t = wmlObjectFactory.createText();

    r.getContent().add(t);
    field.getContent().add(r);

    t.setValue("guess");
View Full Code Here

    {
      System.out.println("P does not contain R!");
      return;
    }

    ObjectFactory factory = Context.getWmlObjectFactory();
    BigInteger ID = BigInteger.valueOf(id);

    // Add bookmark end first
    CTMarkupRange mr = factory.createCTMarkupRange();
    mr.setId(ID);
    JAXBElement<CTMarkupRange> bmEnd = factory.createBodyBookmarkEnd(mr);
    p.getContent().add(index+1, bmEnd);

    // Next, bookmark start
    CTBookmark bm = factory.createCTBookmark();
    bm.setId(ID);
    bm.setName(name);   
    JAXBElement<CTBookmark> bmStart =  factory.createBodyBookmarkStart(bm);
    p.getContent().add(index, bmStart);
  }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.ObjectFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.