Word Automation Code
February 20th, 2006 // 3:30 pm @ Amar
Here
Word.Application wrdApp;
Word._Document wrdDoc;
object oFalse = false;
object oTrue = true;
Word.MailMerge wrdMailMerge;
// Create an instance of Word
wrdApp.Visible = false; // Open the template document.
string TemplateFile = TemplateFilePath + selectedTemplate;
object oFile = Server.MapPath(TemplateFile); wrdDoc = wrdApp.Documents.Open(ref oFile, ref oMissing,ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
wrdDoc.Select();
wrdMailMerge = wrdDoc.MailMerge;
object oSql = “Select * from “ + viewName + ” where Account <> ‘NULL’”;
string ODCFile = Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["ODCFile"]); wrdDoc.MailMerge.OpenDataSource(ODCFile,ref oMissing,ref oMissing,ref oFalse,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oSql,ref oMissing,ref oFalse,ref oMissing);
wrdMailMerge.SuppressBlankLines =
true;// Perform mail merge.
wrdMailMerge.Execute(ref oFalse); if(wrdDoc != null)
{
wrdDoc.Saved =true;
wrdDoc.Close(ref oFalse,ref oMissing,ref oMissing);
}
if(wrdApp != null){
wrdApp.Quit(ref oFalse,ref oMissing,ref oMissing);
}
// Release References.wrdMailMerge = null;
wrdDoc = null;
wrdApp = null;
Posted at DotNetJunkies on Wednesday, October 13, 2004 4:35 PM
Category : Miscellaneous