简体   繁体   English

Excel interop在Office 2007的计算机上运行,​​但在使用Office 2010的计算机上失败

[英]Excel interop works on machine with Office 2007 but fails on machine with Office 2010

I have a C# WPF (.NET 4.0) application that uses Excel interop to read data from an Excel file. 我有一个C#WPF(.NET 4.0)应用程序,它使用Excel互操作从Excel文件中读取数据。

When I run this app on my development machine, which has Excel 2007, it works fine. 当我在具有Excel 2007的开发机器上运行此应用程序时,它工作正常。 When I run it on another machine that has Excel 2010 installed on it, it fails with the following error message: 当我在另一台安装了Excel 2010的计算机上运行它时,它失败并显示以下错误消息:

System.Runtime.InteropServices.COMException (0x80040154): 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)). System.Runtime.InteropServices.COMException(0x80040154):由于以下错误,检索CLSID为{00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80040154未注册类(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG) ))。

The failure occurs when attempting to create a Microsoft.Office.Interop.Excel.Application object, as in: 尝试创建Microsoft.Office.Interop.Excel.Application对象时发生故障,如:

var app = new Application();

My project has a reference to Microsoft.Office.Interop.Excel.dll (version 14.0.0.0, runtime version v2.0.50727), which is located at: 我的项目引用了Microsoft.Office.Interop.Excel.dll (版本14.0.0.0,运行时版本v2.0.50727),它位于:

C:\\Program Files\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Office14\\Microsoft.Office.Interop.Excel.dll 用于Office \\ PIA \\ Office14 \\ Microsoft.Office.Interop.Excel.dll的C:\\ Program Files \\ Microsoft Visual Studio 10.0 \\ Visual Studio工具

I tried to run the app with the default settings on the referenced dll: 我尝试使用引用的dll上的默认设置运行应用程序:

  • Copy Local = False 复制Local = False
  • Embed Interop Types = True 嵌入互操作类型=真
  • Specific Version = True 具体版本=真

I also tried to run the app with the following settings on the referenced dll: 我还尝试在引用的dll上使用以下设置运行应用程序:

  • Copy Local = True 复制Local = True
  • Embed Interop Types = False 嵌入互操作类型=假
  • Specific Version = True 具体版本=真

But on the machine with Office 2010, neither of these attempts worked. 但是在使用Office 2010的计算机上,这些尝试都没有奏效。

Other notes: The machine with Office 2010 is 64-bit w/ Windows 7. My development machine is X86 with Windows XP. 其他说明:Office 2010的计算机是64位w / Windows 7.我的开发计算机是带有Windows XP的X86。

Question

What is causing the "class not registered" exception and how do I fix it? 是什么导致“类未注册”异常,我该如何解决?

Edit 编辑

In response to Alex's answer, I tried building the app as Any CPU, X86, and X64, but it made no difference. 为了回应Alex的回答,我尝试将应用程序构建为任何CPU,X86和X64,但它没有任何区别。 I'm still getting the same "class not registered" error. 我仍然得到相同的“类未注册”错误。

Edit 2 编辑2

Just tried the app on a 32-bit machine with Office 2010. No errors. 刚刚使用Office 2010在32位计算机上试用过该应用程序。没有错误。 So, it could be something wrong with the particular machine, or it could be the combination of 64-bit and Office 2010. 因此,特定机器可能出现问题,或者可能是64位和Office 2010的组合。

Edit 3 编辑3

Okay, so now I've tested it on a different 64-bit machine with Office 2010. Again no errors. 好的,现在我已经在Office 2010的另一台64位计算机上测试了它。再次没有错误。 I think this means something is wrong with the particular machine and it's not my software's fault. 我认为这意味着特定机器出了问题,这不是我软件的错。 Ahh programming. 啊编程。

Preliminary answer: my software was fine and something was wrong with the setup on that particular machine. 初步答案:我的软件很好,特定机器上的设置出了问题。

Edit 编辑

I just found out something that is probably the source of the problem. 我刚刚发现了一些可能是问题根源的东西。 The problem machine has Office, but it is set up as click-to-run (runs off the internet) rather than MSI-based (runs from an EXE). 问题机器有Office,但它设置为点击运行 (从互联网上运行)而不是基于MSI (从EXE运行)。 This means that certain registry settings, DLLs, components, etc. are not available to Microsoft.Office.Interop.Excel , so it fails. 这意味着某些注册表设置,DLL,组件等不可用于Microsoft.Office.Interop.Excel ,因此它失败。

Edit 2 编辑2

That was definitely the problem. 这绝对是个问题。 Just upgraded to a full MSI-based installation of Office, and everything works great. 刚升级到完整的基于MSI的Office安装,一切都很好。

Edit 3 编辑3

Added this as a bug to Microsoft Connect: 将此添加为Microsoft Connect的错误:

https://connect.microsoft.com/VisualStudio/feedback/details/672276/excel-interop-fails-on-machine-where-office-is-installed-as-click-to-run#details https://connect.microsoft.com/VisualStudio/feedback/details/672276/excel-interop-fails-on-machine-where-office-is-installed-as-click-to-run#details

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Office 2007的Microsoft.Office.Interop.Excel - Microsoft.Office.Interop.Excel for Office 2007 如何在没有安装MS Office的计算机上使用Microsoft.Office.Interop.Excel? - How to use Microsoft.Office.Interop.Excel on a machine without installed MS Office? 我可以在装有 MS-Office 2003 的机器上使用 microsoft interop dll 2010 - Can I use microsoft interop dll 2010 on machine having MS-Office 2003 在机器中分离 Microsoft.Office.Interop.Word 实例和 Word 应用程序 - Separate Microsoft.Office.Interop.Word instance and Word app in machine Microsoft Office Interop Excel在Windows 2008 64bit和Office 2007 32bit上无法关闭 - Microsoft Office Interop Excel is not closing on windows 2008 64bit and office 2007 32bit MS Office Excel 2007和2010之间的兼容性 - Compatibility between MS Office Excel 2007 & 2010 Add in 可以在Office 2007中运行Excel VSTO 2010加载项吗? - Can an Excel VSTO 2010 add-in be run in Office 2007? 如何检查Excel文件是2007还是2010 Office - how to check whether excel file is of 2007 or 2010 office 如何使用PIA(2010版本14.0)创建Excel应用程序,并且目标计算机上未安装MS Office客户端 - How to create an Excel application using PIA (2010, version 14.0) and target machine doesn't have MS Office client installed on it Excel Interop Exception(已安装2007,使用Office.Interop.Excel-版本1.6(12))-0x800A03EC HResult - Excel Interop Exception (2007 installed, Office.Interop.Excel used - ver 1.6 (12)) - 0x800A03EC HResult
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM