Exporting to word template

Exporting to word template


I know that this subject have been very discussed here, but I didn't see my doubt anywhere, so here it goes.

I realize that I have use wordmerge in order to create word documents. But first, I have to create the word document, righ?

So, I go to MS Word and create a word document. I put a picture there, some basic text. but now I want to add a customers' address. What do I insert in the document? A rich text content control? A basic one? What text do I insert there?

Then, How do Iactually "tell" MS word that my customers address goes there?

Sorry, but I really need a step to step tutrial on this.

Thank's for the help,

Best Regards,

Dear Francisco,

Although not directly answering you question ;-) I would like to point an alternative approach.

If your end-users are able to read Word 2007 files you can easily create the target document directly in Word's XML format. To understand how this works simply rename any Word 2007 file to have the ".zip" extension and open it. The file you will have to write in your application is the "document.xml" file.

Hope this helps.

All the best,
Pedro Oliveira
Hi Pedro,

Thank's for the reply. I already got to the document.xml part. But, how do I write to that file? Is it necessary to do anything in the end-users pc's?

I had already tried to convert the httpToXml and doenload it as a word document, but I got a forbidden error...
Hi Francisco,

Here goes a rough overview of what you will need to do

In order to have everything setup
1. Create Word 2007 document to serve as a template - let's call it template.docx
2. Store somewhere where it accessible to your application (either in the database or resource for your espace)

Every time you are exporting something
1. Create the XML content equivalent to the document.xml file (a simplistic approach is simply to copy the full content of the document.xml into an expression where you perform whatever replacements you need to do)
2. Save this xml into a temporary file
3. Using the zip extension load the template.docx document
4. Replace the document.xml which can be found int the zip file with the new document.xml
5. Return the resulting file to your user

Hope this helps,
Hi Pedro,

I'be figured out how to work with word merge extension. I just published and opened the wordmergesample oml and there's a simple explanation.

In addittion, I've found out also how to create those fileds to fill with information from the database. You just need to press ctrl+F9, right click, choose edit filed, on the left combo-box choose merge filed and give it a name.

Thank's for all your help.

Bes Regards,

I have the a problem, the word merge process takes an average of about 30 seconds to generate the document.
Is there any solution to solve this delay?

Hi Fernando,

What process are you using to execute the word merge? Are the files involved very large? Is the server under heavy load?

When I worked with word merge in the past, the worst performance I ever had was 10 seconds in one document, with the average being 1-2 seconds.

Do let us know more information about it, so we can try to help.


Paulo Tavares