Gen Walkthrough
Gen Walkthrough
1. targetNamespace
2. xmlns
3. xmlns:mstns
4. name of element and complexType
Add a table in between the Document tags as below, key in the field name also
Place cursor in the cell beside the Supplier cell, then click on Supplier at the XML Structure task pane.
You now can see the Supplier tags
Between each tag put a space as a placeholder, Word at the backend will create a <w:t> element
Now we want to write a program to inject value into the 4 elements defined in the document above,
which are:
1. Supplier
2. Phone
3. Fax
4. AttentionTo
Add reference to the libraries I want to use, they are DocumentFormat.OpenXml (OpenXML SDK),
All the main method of program.cs, define the XMLNamespace
If you didn’t add the Using statement, you can use the resolve context menu to do it. (C# only)
Then take out all the XElements of “w:customXml” which are the XML Schema Tag we put in the Word
document. Use foreach to loop thru the elements