【发布时间】:2013-06-14 14:27:06
【问题描述】:
我想打印出我在程序中生成的 word 文档。因此我使用此代码:
public static void druckeRechnung(object oFilename)
{
object oMissing = System.Reflection.Missing.Value;
List<int> procIds = getRunningProcesses();
_Application wordApp = new Application();
wordApp.Visible = false;
_Document aDoc = wordApp.Documents.Add(ref oFilename);
try
{
System.Windows.Forms.PrintDialog pDialog = new System.Windows.Forms.PrintDialog();
if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
wordApp.ActivePrinter = pDialog.PrinterSettings.PrinterName;
wordApp.ActiveDocument.PrintOut(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,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Fehler beim Drucken");
}
finally
{
aDoc.Close(WdSaveOptions.wdDoNotSaveChanges);
wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges);
aDoc = null;
wordApp = null;
killProcess(procIds);
}
}
我第一次打印文档时,它的工作正常,但之后请求被发送到打印机,没有任何反应。
我做错了吗?有没有更好的方法来实现这一点?
【问题讨论】:
标签: c# automation ms-word word-automation