我想打印出我在程序中生成的 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);
}
}
我第一次打印文档时它的工作方式与它应该的一样,但之后请求被发送到打印机并且没有任何反应。
我做错什么了吗?有没有更好的方法来实现这一点?