Prabakar

I am developing an application that uses Interop objects Interop.Word, Interop.Excel.

I am supposed to print list of documents of formats .doc,.xls. I have to get Print Preferences from the user by showing Print Dialog. and to print all those listed documents with the same preferences.

I tried with Word.Dialogs collection. But by this way it will show dialog for each document to be printed. But for me it should shown only one time.

Printing preferences like, paper orientation, paper size, color or monochrome etc to be applied.

How can it be posssible

Is there a way to do these things

Word, Excel Interop Type library are are 2003 version correponding Type library.,

Iam having trouble in disposing those COM objects also. Look at the following snippet and correct me.

Code Snippet

Word.ApplicationClass appWord = new Microsoft.Office.Interop.Word.ApplicationClass();

try

{

Word.Document docTemp = appWord.Documents.Open(ref objFileName, ref Missing, ref objTrue, ref objFalse, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);

//Word.Dialog dlg = appWord.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint];

//dlg.Show(ref Missing);

//appWord.Options.PrintDraft = true;

//appWord.Options.PrintDrawingObjects = true;

appWord.PrintOut(ref objTrue, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref objFalse, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,ref Missing);

docTemp.Close(ref objFalse, ref Missing, ref Missing);

}

catch (Exception ex)

{

MessageBox.Show("Error " + ex.ToString());

}

finally

{

if (appWord != null)

{

appWord.Quit(ref objFalse, ref Missing, ref Missing);

System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord);

appWord = null;

}

}

Thanks...




Re: Visual C# General Print multiple documents with same printing preferences and Interop Dispose problem

Figo Fei - MSFT

Hi, Prabakar

What's problem you met with while disposing resources It looks ok.

About printing the document in word, you can check the following resources: http://www.codeproject.com/Purgatory/WordPrinting.asp df=100&forumid=199084&exp=0&select=1966951

http://www.codeproject.com/useritems/Word2007Automation.asp

Thanks




Re: Visual C# General Print multiple documents with same printing preferences and Interop Dispose problem

Prabakar

Thanks for your post.

Reg. Disposing now the problem seems to be Ok. but some times, Excel , winword processes are left without getting disposed. I could see them in the task manager. But now thats not a major issue for me now.

The links you have posted says about the thing what i have already. But here my requirement is about printing multiple word documents at a stretch... without showing print dialog for each document. I have to get the print preferences only one time and has to apply those to all other documents.






Re: Visual C# General Print multiple documents with same printing preferences and Interop Dispose problem

Figo Fei - MSFT

Hi, Prabakar

About Disposing issue, I noticed release the appWord but forget to release the docTemp object, so the disposing should be like:

Code Snippet

appWord.Quit(ref objFalse, ref Missing, ref Missing);

System.Runtime.InteropServices.Marshal.ReleaseComObject(docTemp);

System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord);

docTemp = null;

appWord = null;

GC.Collect();

Thanks






Re: Visual C# General Print multiple documents with same printing preferences and Interop Dispose problem

Prabakar

Yeah i should include that also. thanks