visual-studio-2012 - 加载类型库/DLL 时出错(Microsoft.Office.Interop.Excel.Application)

标签 visual-studio-2012 ms-office office-interop office-2013

我正在尝试通过 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)).

enter image description here

在我将 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/

相关文章:

vba - 如何在 Word 表格中复制一行?

c# - 办公文件转PDF

c++ - 如何在英特尔实感(Visual C++)中保存图像

c# - 使用 Visual Studio 2010 (VSTO) 进行 Office 开发,需要考虑的事项

c# - Outlook ItemAdd 事件未触发

vsto - 以编程方式从功能区获取功能区控件

php - 使用 PHP 在 docx 文件中查找换行符

c# - Visual Studio 2012 输出窗口中的不同颜色

wpf - 如何在 Visual Studio 2012 中使用 Blend 打开 WPF 项目?

c++ - 为什么LNK2005错误消失了?