Excel的互操作工作机器上的Office 2007,但使用Office 2010无法上机 [英] Excel interop works on machine with Office 2007 but fails on machine with Office 2010

查看:132
本文介绍了Excel的互操作工作机器上的Office 2007,但使用Office 2010无法上机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Excel的互操作从Excel文件中读取数据的C#WPF(.NET 4.0)应用程序。

I have a C# WPF (.NET 4.0) application that uses Excel interop to read data from an Excel file.

在我自己的计算机上运行该应用程序,其中有Excel 2007中,它工作正常。当我有Excel 2010中安装了另一台机器上运行它,它失败,出现以下错误信息:

When I run this app on my development machine, which has Excel 2007, it works fine. When I run it on another machine that has Excel 2010 installed on it, it fails with the following error message:

System.Runtime.InteropServices .COMException(0x80040154的):(从HRESULT异常:0x80040154的(REGDB_E_CLASSNOTREG))80040154没有注册类:用CLSID {00024500-0000-0000-C000-000000000046}失败,原因是以下错误检索COM类工厂的组件。

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)).

试图创建一个 Microsoft.Office.Interop.Excel.Application 对象,如:

The failure occurs when attempting to create a Microsoft.Office.Interop.Excel.Application object, as in:

var app = new Application();



我的项目有 Microsoft.Office.Interop.Excel.dll参考(14.0.0.0版,运行版V2.0.50727),它位于:

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:

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

C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll

我试图与被引用的DLL的默认设置运行应用程序:

I tried to run the app with the default settings on the referenced dll:


  • 复制本地=假

  • 嵌入互操作类型= TRUE

  • 针对版本= TRUE

我也试图与被引用的DLL以下设置运行应用程序:

I also tried to run the app with the following settings on the referenced dll:


  • 复制本地=真

  • 嵌入互操作类型=假

  • 针对版本= TRUE

但在。该机使用Office 2010,无论这些尝试的工作。

But on the machine with Office 2010, neither of these attempts worked.

其他说明:与Office本机2010是64位的W / Windows 7的我的机器是X86与Windows XP。

Other notes: The machine with Office 2010 is 64-bit w/ Windows 7. My development machine is X86 with Windows XP.

是什么原因造成了未注册类异常如何解决呢?

What is causing the "class not registered" exception and how do I fix it?

修改

在回应Alex的答案,我试图构建应用程序的任何CPU,X86和X64,但它并没有区别。我仍然得到同样的类没有注册的错误。

In response to Alex's answer, I tried building the app as Any CPU, X86, and X64, but it made no difference. I'm still getting the same "class not registered" error.

编辑2

刚试过的应用程序在32位计算机上与Office 2010没有错误。因此,它可能是与特定的机器做错了事,也可以是64位和Office 2010的结合。

Just tried the app on a 32-bit machine with Office 2010. No errors. So, it could be something wrong with the particular machine, or it could be the combination of 64-bit and Office 2010.

修改3

好了,现在我已经与Office 2010同样没有错误测试了不同的64位计算机上。我觉得这意味着什么是错与特定的机器,它不是我的软件的错。 。啊编程

Okay, so now I've tested it on a different 64-bit machine with Office 2010. Again no errors. 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.

修改

我刚刚发现的东西,可能是问题的根源。有问题的机器有办公室,但被设置为的点击即可运行(运行从互联网上),而不是的基于MSI的(从EXE运行)。这意味着,某些注册表设置,DLL文件,组件等都是不能使用的Microsoft.Office.Interop.Excel ,所以会失败。

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). This means that certain registry settings, DLLs, components, etc. are not available to Microsoft.Office.Interop.Excel, so it fails.

编辑2

这肯定是问题。刚刚升级到完整的基于MSI的Office的安装,一切的伟大工程。

That was definitely the problem. Just upgraded to a full MSI-based installation of Office, and everything works great.

修改3

添加这个bug微软连接:

Added this as a bug to Microsoft Connect:

https://connect.microsoft.com/VisualStudio/feedback /信息/ 672276 / Excel的互操作 - 失败 - 在机器的地方办公,在安装-AS-点击即可运行#详细信息

这篇关于Excel的互操作工作机器上的Office 2007,但使用Office 2010无法上机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆