what's wring?
here are my code
- Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
CTCustomXmlBlock ctCustomXmlBlock=new CTCustomXmlBlock();
CTCustomXmlPr ctCustomXmlPr=new CTCustomXmlPr();
ctCustomXmlBlock.getContent().add(ctCustomXmlPr);
ctCustomXmlBlock.setElement("customizedElement");
CTAttr ctAttr=new CTAttr();
ctAttr.setName("testAttrName");
ctAttr.setVal("testValue");
ctAttr.setParent(ctCustomXmlPr);
ctCustomXmlPr.getAttr().add(ctAttr);
P p=new P();
R r=new R();
Text t=new Text();
t.setValue("marked text here");
r.getContent().add(t);
p.getContent().add(r);
ctCustomXmlBlock.getContent().add(p);
wordMLPackage.getMainDocumentPart().getContent().add(ctCustomXmlBlock);
wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/OUT_withCustomXml.docx") );