OpenXML: Creating reusable Content Controls with binding
I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK.
The thing is I want too be able to define the Content Controls already bounded in some sort of template so other people can create the real document template the xml will be attached to. Ok not sure people will undestand what I mean so I will explain further.
There may be many different document templates that will use the same XML data and so the same Content Controls. It's up to someone else to create the document.
Scenario: Some dude that's not a programmer needs to create a new form for the usual info because of some changes ( new layout or somehting ). This has nothing to do with the XML info, that stays the same.
Optimal solution for "some dude" would be to create the document in Word and drag the Content Controls into place ( or some solution si开发者_Go百科miliar). Then when the XML gets added to the document there is no problem as the Content Controls are pre-binded.
Now there are a few points here:
1) Can Content Controls be pre-binded? If there is no XML at the path won't it just stay empty without problems?
2) Will binding Content Controls to CustomXML's like this still work in future versions of Word because of the i4i lawsuit?
3) Is there perhaps another optimal solution better then this?
Thanks in advance.
EDIT:
To be more clear. I wan't to create Content Controls that would have some name to identify them and a databound xpath. However at that moment there is nothing at the path.
Another user comes in and creates a form, decides the layout on so on, and then adds the Content Controls into the places he wants the info to be.
Later on the info for item X is requested using the new form. So a copy of that form will be taken and the CustomXML will be added into the Docx file. Now because the XML shchema was known beforehand and used when deciding the paths for the CC's this XML data will be bound to the Content Controls.
One great option would be to use VSTO (Visual Studio for Office) to build a set of document templates that have your prebinding code attached. These two articles provide a good start into looking into this type of a solution:
- Creating a Template By Using Content Controls
- Binding Content Controls to Custom XML Parts
There are two threads that discuss some details of this: 1 and 2.
One of the benefits about using VSTO is that you can hook the Content Control events: Content Control Event Model in Word 2007.
If VSTO is not an option, you can always look at Add Custom XML Parts to Documents Without Starting Microsoft Office.
This should be very straightforward. Custom controls are not impacted by the i4i lawsuit and you can name them using the tag property in each control (warning - it is limited to 64 characters).
精彩评论