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?

Coordinator
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.
html:

<span>[REPLACE_TOKEN#1]</span>

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=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +

                        xml.InnerXml +

                    "</w:fldSimple>";
...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? :-)

 



 

Coordinator
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:
http://stackoverflow.com/questions/4793695/manipulating-word-2007-document-xml-in-c-sharp
http://social.msdn.microsoft.com/Forums/en-CA/oxmlsdk/thread/287c607b-e542-454d-ac57-fe1ec72ab2d8

Hope it helps