Excel.Application异常

时间:2019-04-03 18:56:08

标签: c# excel

在应用程序的主要部分中,我将此行称为:

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

它给了我一个例外:

System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).'

我试图在x86,x64模式下运行调试是相同的结果。

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试这样声明它们,完全合格:

Microsoft.Office.Interop.Excel.Application xlapp =新的Microsoft.Office.Interop.Excel.Application();

                 Microsoft.Office.Interop.Excel.Application xlApp;
                 Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                 Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;