Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET and Creating / Populating Word Documents

Status
Not open for further replies.

SonJ

Programmer
Joined
Oct 24, 2002
Messages
166
Location
GB
Hi,

I have a web application were a user fills in a form and the details are saved to the database. One of the requirements is for admin to view a copy of the record and then be able to generate a word document by clicking a button. Only three of the values saved will be "copied" across into the word file. There is a sample format that they want to use (approx 3 pages long) which uses tables. These 3 values have to be placed in the correct cell in the correct table.

I am a little perplexed as to how I will achieve this and am currently looking to assess the best way forward. If anyone has any hints, tip, references that they would like to share it would be much appreciated.

Thanks in advance,
SonD
 
Hi

If the details are in the database, then you can use Mail Merge in Word to do what you want to achieve. You need to create a Stored Procedure to get the data that you want to populate into the document. Then you need to create a Document Template, and set it up to use Mail Merge. You will need to have a play around with this feature, as I can't remember exactly what you have to do. In effect though, you need to specify the Stored Procedure you have written as the data source for the mail merge, and then insert the fields into the document.

You can then open the template from your ASP.NET page, and it will populate the fields. You will need to pass in any parameters at this point.

As Word is generally a client app, you will need to run this from client script. However, when I did it before, I generated tyhe client script on the server, and the used Response.Write to get it back to the client. This enabled me to use server controls, and also to set up the correct database info including parameters.

This is a quick and easy way to insert fields into a Word Document. There are some pitfalls though, for example if the target database changes, then the templates need to be regenerated to look at the correct database.
 
Thanks jby1.

This sounds exactly like what I need to do. If you have any references / hints / tips then they would be much appreciated.

SonD
 
Hi

Does anyone know if it is possible to specify a SQL Server stored procedure as the data source for a mail merge in word. If so, can you let me know what I need to do.

Thanks in advance,
SonD
 
Hi

When I did it before, it was easy, but now I have a new version of Word and it only seems to give access to Tables and Views. Hence you would probably need to set up a view.

I am sure there must a way of pointing it to a Stored Procedure though, just don't have the time to figure it out right now :-(

If you do manage to work it out, then please post your solution though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top