Page 1 of 1

rewriting of sdt's with docx4j

PostPosted: Thu Jan 13, 2011 11:47 pm
by Lars
Hello,

I've got some documents with content controls in it (sdtBlock).

With this method I was able to read it after casting it to a sdtBlock:
...getMainDocument.getJaxBElement.getBody.getEG...get(x)...

First, Is there a better possibility without casting of the element?

Also, i need to rewrite the content of the sdtBlock with docx4j (not adding a new one) but I found no way to do this. Is there a possibility?

kind regards

Re: rewriting of sdt's with docx4j

PostPosted: Fri Jan 14, 2011 12:50 am
by jason
Lars wrote:First, Is there a better possibility without casting of the element?


Unfortunately not; there are different objects for block level, inline, table row, and table cell sdts. (Microsoft's OpenXML SDK is similar in this respect)

Lars wrote:Also, i need to rewrite the content of the sdtBlock with docx4j (not adding a new one) but I found no way to do this. Is there a possibility?


Sure, SdtBlock has

Code: Select all
public SdtContentBlock getSdtContent()


and SdtContentBlock has

Code: Select all
public List<Object> getEGContentBlockContent()


which contains all the content.

Re: rewriting of sdt's with docx4j

PostPosted: Fri Jan 14, 2011 7:13 pm
by Lars
Ok.

Due to I got problems with the replacement of the sdtContent I just toke the sdtBlock and used the marshal and unmarshal methods of XMLUtils to rewrite the content.

kind regards
Lars