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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailmerge in MS Word using ASP.NET!

Status
Not open for further replies.

maniacmaniar

Programmer
May 9, 2008
6
US
Hi guys: I have a problem that I havent been able to resolve. Basically, I have an ASP.NET application that the users will use to select records and then do a mail merge. My code is able to do the merge, but the problem is that the mailmerge toolbox in MS Word is disabled (grayed out). I need this to be enabled because I want to give the users the ability to add/remove any fields from the document. It would be great if someone can help me in this issue. By the way, I am using MS Word 2003 and running XP.

Thanks.

Here is the code that I am using:

Code:
ApplicationClass myWordApp = new ApplicationClass(); // our application

Document myWordDoc = new Document(); // our document

object missing = System.Reflection.Missing.Value; // our 'void' value 
object filename = "C:/sample_merge_doc.doc"; 

object destination = "C:/MyNewDocument.doc"; // our target filename

object notTrue = false; // our boolean false

myWordApp.Visible = false; // tell word not to show itself so that we can do everything in the background

myWordDoc = myWordApp.Documents.Add(ref filename, ref missing,ref missing,ref missing);

object oconn = "DSN=dsnName;uid=uname;pwd=passwd;"; 
Object oFileFormat = System.Type.Missing;

Object oMissing = System.Type.Missing; 
Object oFalse = false;

Object oTrue = true; 
Object oSubType = System.Type.Missing;

string dsName = null;

myWordDoc.MailMerge.OpenDataSource(dsName, ref oFileFormat, ref oMissing, ref oTrue, ref oMissing, 
ref oFalse, ref oMissing, ref oMissing, ref oTrue,

ref oMissing, ref oMissing, ref oconn, ref query, ref oMissing, ref oMissing, ref oSubType);

myWordDoc.MailMerge.Execute(ref oFalse);

myWordApp.Visible = true;
 
if this is an asp.net app that means this code is on the server, not the client. durning development this works because your local box is also the server. once you put this into production msword will launch on the server, not the client. it will also require ms word to be installed on the server because use need access to the api.

options:
1. create a desktop app which does this for you. you may need to account for OS/Office versioning.
2. use xml/xslt to create a text document. this is essentially creating a simplified version of mail merge. if users require the ability to modify what information is shown, then you need to create this as well.
3. have the user open/download the template and merge the data, select the fields and upload to the website for whatever.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I don't understand. Why would you want to open Microsoft Word on the server? Are you expecting your users to use your application when physically sat at the server?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Jason:
Option 3 that you mentioned is what I am trying to achieve. As I mentioned in the original post, the users can use the above code to provide the template and then do the merge. Currently I hardcoded the template name in the variable named "filename", but in reality I let them select a template and then do the merge.

The problem is that once they do the merge and see the word document, they cant select any fields because the mailmerge toolbox is grayed out.

Thanks for your help.
 
Jason, as far as your comment about word having to be installed on the server, you are right that it will have to installed on the server otherwise this approach wont work. I have done that, but if there is a better approach, please let me know. I saw another post somewhere about using DSOFILE, but I wasnt able to get it to work.

Faisel.
 
Mark, as I said, my users will provide a template, select the records from the query that they run on my application, and then do the mailmerge on the selected records using the template. Thats why I am doing this. Are there any better approaches?
 
to marks point, why is this happening on the server? this is ususally an action preformed on a local machine.

I understand posting the question in this forum because you're desiging a webpage. Really this issue has nothing to do with asp.net it releates to the office api. I would try a forum dedicated to Office. if that does not exist try vb or c# forum (which ever language you are using)

It may be that this type of functionality is not readily/easily available. just reading it sounds awakwar to launch word on a server, to mail merge, to do the next step.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top