Page 1 of 1

Editing a single content control without data binding

PostPosted: Fri Dec 14, 2012 9:57 am
by wmccullough
I apologize if this has been asked before, I spent roughly four hours searching before I decided to open a thread about it.

I have come from using C# to manipulate word 2007 documents with the OpenXML SDK. Manipulating content controls can be done fairly easily if you know the tag of the content control. I am hoping to be able to populate text strings into richtext content controls in word 2007 without using xml binding.

I have tried to cycle through the JAXBElements to find content controls by name, but this seems to be very difficult to do consistently when documents can change. Is there any direct way to do this without using xml based binding?


Thank you in advance.

Re: Editing a single content control without data binding

PostPosted: Fri Dec 14, 2012 12:07 pm
by jason
BindingTraverserNonXSLT contains an example of how to traverse the document looking for content controls.

https://github.com/plutext/docx4j/blob/ ... nXSLT.java

see line 109 invoked from line 71

The alternative approach would be to use XPath. I wouldn't recommend this using the JAXB reference implementation, but you might have better luck with moXy.

Either way, you'd still be looking for the sdt with the matching tag.

Re: Editing a single content control without data binding

PostPosted: Sat Dec 15, 2012 12:13 am
by wmccullough
Thanks for the information, this is exactly what I was looking for.