我正在尝试通过 C# 创建 Excel 文档。当我运行该应用程序时,出现以下错误:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
在我将 Visual Studio 从 2010 年升级到 2012 年之前,它运行良好。我还将 Office 从 2010 年升级到 2013 年。
- 输出窗口没有错误/警告。
- 添加了 Microsoft.Office.Interop.Excel 引用
最佳答案
我为这个错误苦苦挣扎了几天。我终于找到了解决办法。
出现这种情况是因为我安装了 Office 2013,而不是我在旧版本项目中使用的 Office 2010。升级 Office 后,该项目不再能够链接 Excel 引用。
尽管我引用了新的 Excel 库 15.0,但它不起作用。
我所做的是:
- 删除 Excel 引用 (Microsoft.Office.Interop.Excel)。版本 15.0,就我而言。
- 安装 Microsoft Excel(无论您使用的是哪个版本。我的版本是 2010)
- 添加 Excel 引用(旧的。 就我而言,版本 14.0)
关于visual-studio-2012 - 加载类型库/DLL 时出错(Microsoft.Office.Interop.Excel.Application),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14107296/