0

プログラムで生成した 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);
    }
}

ドキュメントを初めて印刷するときは、正常に機能しますが、その後は要求がプリンターに送信され、何も起こりません。

私は何か間違ったことをしていますか?これを実現するためのより良い方法はありますか?

4

2 に答える 2