2017-03-04 180 views
1

我正在使用C#和Word Interop来自动化邮件合并。我想用默认选项将每个合并文档打印到默认打印机,但不希望每次都显示打印选项对话框。我怎样才能做到这一点?当我在客户机上试用此代码时,PrintOut方法被调用时会显示一个打印选项对话框。这里是我的代码:如何在C#中打印Word文档而不显示打印对话框

Word.Application oWord = new Word.Application(); 
oWord.Visible = false; 
Word.Document oWordDoc = new Word.Document(); 
object oTemplatePath = Path.Combine(baseDir, fileName); 
oWordDoc = oWord.Documents.Add((ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); 
object copies = "1"; 
object pages = ""; 
object range = Word.WdPrintOutRange.wdPrintAllDocument; 
object items = Word.WdPrintOutItem.wdPrintDocumentContent; 
object pageType = Word.WdPrintOutPages.wdPrintAllPages; 
object oTrue = true; 
object oFalse = false; 
oWordDoc.PrintOut(ref oTrue, ref oFalse, ref range, ref oMissing, ref oMissing, ref oMissing, ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing); 
+0

您是否尝试过设置[oWord.ActivePrinter](https://msdn.microsoft.com/en-us/library/office/ff821995.aspx)? – stuartd

+0

@stuartd:我还没有尝试过,但这是需要在多台客户端计算机上运行的东西,而且我无法知道它们的打印机名称。这个想法是我的功能使用默认打印机与所有默认选项。 –

回答

0

我使用这个,它适用于单词文档。

 Process p = new Process(); 
     p.StartInfo = new ProcessStartInfo(); 
     p.CreateNoWindow = true; 
     p.Verb = "print"; 
     p.FileName = file; 

     p.Start(); 
相关问题