This project has moved and is read-only. For the latest updates, please go here.

Merge Fields

Oct 13, 2011 at 3:24 PM

Hi, i have a question: is there any workaround to add a merge field to the generated document?

Somekind of a custom tag that could be interpreted as a merge field?

Oct 13, 2011 at 4:50 PM

you can still define a "token text" in your html file and once the document is generated, you replace it with your merge field.


Oct 13, 2011 at 4:56 PM
Edited Oct 13, 2011 at 5:08 PM

Hi, i know that creating a merge field can be done by replacing the innerXML of a paragraph run:

                    xml.InnerXml =

                    "<w:fldSimple w:instr=\" MERGEFIELD  " + xml.InnerText + "  \\* MERGEFORMAT \" xmlns:w=\"\">" +

                        xml.InnerXml +

...but i think i don't understant what you said. How can i replace a specific content of the word document when it has already been created? 
Can it be done with HtmlToOpenXml?

Oct 13, 2011 at 5:38 PM
Edited Oct 13, 2011 at 5:39 PM

How can i change the xml of the function ProcessSpan? :-)



Oct 14, 2011 at 12:25 PM

you should not change the xml of the function ProcessSpan.
Instead, you should let HtmlToOpenXml generate the document.

Using classic OpenXml API, you can find some text and replace its content. When you start the conversion, you should have used the MainDocumentPart class.
So some XPath queries later and you will replace the token.
You can find some examples here:

Hope it helps