Forum Moderators: open
This is driving me mad - been working on this for days now, and I'm just not getting anywhere.
I'm using Microsoft Word from my ASP.NET project, to load a template (.DOT file) which includes a number of bookmarks, then populating the template with data, and streaming the result to the user's browser.
This works fine for a single page (ie, one template to produce one page of the mail merge). The problem arises when I need to create 2 or more instances of the template with different data being inserted (for example, producing the same letter for Customer 1 and Customer 2).
I think I'm getting myself into a mess, and as a result, the documents that are produced look as follows (simplified)....
-------------------------------------------
(template)
Name: (bookmark1)
Postcode: (bookmark2)
First Customer's name = Jimmy
First Customer's postcode = HD1 3RT
Second Customer's name = Harry
Second Customer's postcode = HD2 4FD
(first document produced)
Name: Jimmy
Postcode: HD1 3RT
(second document produced)
Name: HarryJimmy
Postcode: HD2 4RDHD1 3RT
-------------------------------------------
The bookmarks are not replaced with each subsequent document that's created, instead the data is added. It seems that the original template that is being used is being added to, and subsequent documents are seeing the data previously entered as the text of the template.
The only way I've found round this is to close the WordApplication object after each document has been created, and open a new instance on each iteration, which creates a HUGE amount of overhead.
Has anyone got any suggestions, or places I can look? I know this is quite vague, but I'd really appreciate any pointers from anyone - I'm feeling quite out of my depth with this one, and feeling rather frustrated!
Cheers,
B
To keep you from pulling you hairs out using the word interop, I would strongly recommend to 3rd party component in stead of using the interop.
The interop is know to cause stability issue's on the webserver and the api is quite complex.
Seaching for asp.net word component in Google should give you some starting points.
Regards,
Ward