Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

We have written a program that uses templates(user defined) created in docx files to create agreement documents. The agreement file is typically about 50-60 pages.
We use parameters in the format of |p|customername|p| in the template file and use the openxml library to replace the parameters with the actual data.
The problem is, some parameters are replaced and some are not. When we opened the template file as an xml(document.xml), we found that MSWord has stored the "|p|" in a separate <w:r xmlns:w="#unknown"> tag and "customername" in a separate <w:r> tag (Actually for some parameters even the "|" is stored in a separate tag). When we search for the parameter as one single word, it is not found.
Is there any way of controlling the way MSword stores the words or is there any other solution for this problem?

Thanks in advance
Posted
Comments
Manfred Rudolf Bihy 2-Jan-11 10:08am    
Updated my answer with a helpful CP project you can use.

1 solution

Hello Suresh!

I just found this link where they are adressing just your problem:

How to replace content in template docx document and Open XML SDK 2.0 (Aug 09)?[^]

First answer to the question mentions "Document Reflector Tool" which might be helpfull in your quest.

Modification:
You can let your customers enter document variables/fields. They just need to do Insert->Quick Parts->Fields->Doc Variable, enter name of variable and here on CP there is an example of how to fill these fields with data:
Example: Fill Mergefields in .docx Documents without Microsoft Word[^]
End modification


Best Regards,
Manfred
 
Share this answer
 
v2
Comments
Suresh Belur 2-Jan-11 9:36am    
Hi Manfred,
Thanks for the suggestion, but we are actually using the a similar methodology. The problem is some parameters get replaced and some do not. This is because we have no control on how MSWord stores it. We cannot use Content Controls because the templates are created by our customers and we want it to be very simple for the customers to create
Manfred Rudolf Bihy 2-Jan-11 10:00am    
Well I do have an idea that worked for me before: Why not have the field placeholder surrounded by three to six Xs. Three Xs sufficed for us because in the "real world" these words don't sneak in by accident and it's still easy enough to type in. Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900