471,316 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

How to open word file on background for process.

Ang
Hi,

I want to open a word file on background instead of showing the process
on client's screen. And then do mailmerge, after that allow user to
saveas. (user simply click the button and IE will ask user to open or
save as the file)

Below is the code but I donno how to do it on background. It's an aspx
program, thanks.

Ang

using Word = Microsoft.Office.Interop.Word;
----
Word.Application WordApp = new
Microsoft.Office.Interop.Word.Application();
object missing = System.Reflection.Missing.Value;
object falseValue = false;
object trueValue = true;

private void WordProcess(string openDoc, string openXls, string saveDoc)
{
object fileName = openDoc;
Word.Document doc = WordApp.Documents.Open(ref fileName, ref missing,
ref falseValue, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref trueValue, ref
missing, ref missing, ref missing, ref missing);
object linkTo = openXls;
object query = "SELECT * FROM `DataSource$`";

try
{
doc.MailMerge.OpenDataSource(linkTo.ToString(), ref missing, ref
missing, ref missing, ref trueValue, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref query,
ref missing, ref missing, ref missing);
doc.MailMerge.Execute(ref missing);
}
catch (Exception ex){}
finally
{
try
{
//doc.Save();//save word
CloseApp();//close word app
}
catch (Exception ex) {}
}
}

private void CloseApp()
{
WordApp.Documents.Close(ref trueValue, ref missing, ref missing);
WordApp.Quit(ref trueValue, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(WordApp);
GC.Collect();
//this.KillExcelProcess();
}

*** Sent via Developersdex http://www.developersdex.com ***
Sep 11 '08 #1
0 1737

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ruslan | last post: by
4 posts views Thread by Bishman | last post: by
10 posts views Thread by Antoine De Groote | last post: by
5 posts views Thread by Alan T | last post: by
2 posts views Thread by AY Xu | last post: by
2 posts views Thread by hharry | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.