OpenXML and Word replace


New member
Jan 11, 2014
Programming Experience
Hey all,
I have a word template with certain words in it like for instance [companyName] and [contactName] Which i want to replace and output to the browser.
I tried a very simple approach by searching the body and replacing those string instances. AT first glance it seemed to work but then i noticed one of the (i have multiple) [companyName] was not replaced. I went throught the xml to check and for some reason Word split that word up into 3 runs. So alltho the markup for the entire word is the same word would split it up like

They have some sort of matching id on them tho.
Is there any way to do this replace properly? Iterating the runs gives the same problem, he will never find the exact String inside and thus not replace it.
What are the probable ways to tackle this problem? Prefereably with some code examples?

I used to use interop but this requires word to be installed on the server and i don't want that anymore. I want to use a clean way. If there is an alternative to openXML feel free to let me know also. But for now i have only experimented with openXML
Top Bottom