使用xlDialogPrint.show方法时,为什么我在c#中显示Dialog类的Show方法失败?

时间:2014-05-22 18:04:59

标签: c# excel

我正在尝试使用visual studio在C#中打印Microsoft Excel文档,每次尝试执行这段代码时,我都会得到一个Dialog类的Show方法失败异常:

bool userDidntCancel =
       ExcelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrint].Show(
           Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing,
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

以下是我正在使用的完整代码:

            Excel.Application ExcelApp = new Excel.Application();

            Excel.Workbook wb = ExcelApp.Workbooks.Open(
            PATH,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];

    try
    {
        bool userDidntCancel =
           ExcelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrint].Show(
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    }
    catch
    {
        ExcelApp.Quit();
        File.Delete("Container Status.xls");
    }

我有什么遗失的吗?

0 个答案:

没有答案