本文介绍了试图做办公自动化与Excel 2007,但使用Excel 2003中不断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:

Windows XP中机 -
都Excel 2007和Excel 2003中安装(按顺序,不按时间顺序)结果
C#3.5

Windows XP machine
Both Excel 2007 and Excel 2003 installed (in that order, not chronologically).
C# 3.5

问题:

当我使用PIA的做一些办公自动化,我用下面的代码行:

When I use the PIAs to do some Office automation, I use the following line of code:

var excel = new ApplicationClass();



该PIA的版本专指它为Excel 12,结果
C:\\ \\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll结果
但是:

The PIA's version specifically refers to it as Excel 12.
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll
But:

 excel.Version;//this is 11.0 instead of 12.0

因此,当我尝试打开与延伸的.xlsx文件,它警告我有关的文件转换功能丧失,并与2003年Excel中打开它,我敢肯定它具有与办install命令是2007 - > 2003年,但我不能在我的机器上卸载2003 b / C我们有一个使用Excel 2003中

Thus, when I try to open a file with extention .xlsx, it warns me about lost functionality in the file conversion, and opens it with excel 2003. I am pretty sure it has to do with the install order being 2007 -> 2003, but I can't uninstall 2003 on my machine b/c we have some office automation on our webserver for an unrelated project that uses excel 2003.

我已经看过了Policy.11.0.Microsoft.Office.Interop.Excel.config的东西,但它说:

I've looked at the Policy.11.0.Microsoft.Office.Interop.Excel.config stuff, but it says

<bindingRedirect oldVersion="11.0.0.0" newVersion="12.0.0.0"></bindingRedirect>



所以,我很茫然。为什么我不能告诉COM互操作哪个版本的Excel使用?

So, I am at a loss. Why can't I tell the COM Interop which version of Excel to use?

推荐答案

您无法通过编程命令中使用的Excel版本。该PIA的唯一决定哪些接口或对象模型,要针对发展中国家。但哪个版本的Excel实际运行是由注册表控制。

You cannot programmatically command which version of Excel to use. The PIAs only dictate which interface, or object model, you are developing against. But which version of Excel is actually running is controlled by the registry.

当涉及到运行PIA的,但是,你会真正对运行系统上安装的最高级别的PIA。所以,如果你开发针对Excel 2003中PIA,但客户端具有Excel 2007中的Excel 2007中PIA,您的代码将运行针对Excel 2007中PIA - 它应该运行正常,因为Excel 2007中PIA是向后兼容。也就是说,每一个编号较高的PIA版本(和Excel对象模型)是向后兼容反对旧的PIA和老年Excel对象模型编译的命令。请注意,如果客户有两个机器上的Excel 2007和Excel 2003 PIA的,那么更高版本的PIA将加载,无论哪个版本的Excel正在运行的 - 这样的Excel 2007 PIA将运行,如果两个PIA的是可

When it comes to running the PIAs, however, you will actually run against the highest-level PIA installed on the system. So if you develop against the Excel 2003 PIA, but the client has Excel 2007 with the Excel 2007 PIA, your code will run against the Excel 2007 PIA -- and it should run fine, because the Excel 2007 PIA is backward compatible. That is, each higher-numbered PIA version (and Excel object model) is backward compatible to commands compiled against an older PIA and older Excel object model. Note that if the client had both the Excel 2007 and Excel 2003 PIAs on the machine, then the higher versioned PIA would load, regardless of which version of Excel is running - so the Excel 2007 PIA would run, if both PIAs were available.

好了,你不要有很多在你对开发实际上并没有控制这PIA实际上将在客户端机器上运行PIA的,因为PIA控制。

Ok, so you don't have a lot of control over the PIAs because the PIA that you developed against does not actually control which PIA will actually be running on the client machine.

您没有很多控制在其中的Excel版本是推出。例如,当你通过创建一个新的Excel实例:

You don't have a lot of control over which version of Excel is launched either. For example, when you create a new Excel instance via:

Excel.Application excelApp = new Application();



加载Excel应用程序是根据当前的版本在注册表中设置设置。当前版本的保存位置为:

The Excel application loaded is set according to the current version set in the registry. The current version is saved at:

HKEY_CLASSES_ROOT\Excel.Application\CurVer

看起来不是'Excel.Application像你的情况将有Excel.Application.11'的默认值CURVER键, 0.12。单独更改,这可能做的伎俩,但我宁愿做一个修复,而不是确保所有的注册表设置都正确校正。 (我不可能知道所有的设置应该是什么。)好吧,我刚刚发现另一个问题:你也需要改变:

It looks like the 'CurVer' key in your case will have a default value of 'Excel.Application.11', instead of 'Excel.Application.12'. Changing this alone might do the trick, but I would prefer to do a repair instead to make sure that all the registry settings are corrected properly. (And I couldn't possibly know what all the settings should be.) Ok, I just found another one: you would also need to change:

[HKEY_CLASSES_ROOT\CLSID\{00024500-0000-0000-C000-000000000046}\ProgID]

举办Excel.Application.12的值。但我强烈建议运行维修来代替。我不知道其他的设置可能需要做什么改变,由专人因此改变它们是一个有点冒险。

to hold a value of "Excel.Application.12". But I would strongly recommend running a repair instead. I don't know what other settings might need to be changed, so changing them by hand is a bit risky.

此外,你会发现下面的键以及

In addition, you should find the following keys as well:

HKEY_CLASSES_ROOT\Excel.Application.11
HKEY_CLASSES_ROOT\Excel.Application.12

由于这些是已安装的Excel版本。

Because these are the versions of Excel that you have installed.

(请参见再讨论。)

我敢肯定它与
做安装顺序是2007 - > 2003

是的,这是100%正确。你可以尝试在Excel 2007中运行的修复,这将是最容易做的事情。如果这也不行,那我就同时卸载,然后重新安装它们。我想卸载Excel 2003中,然后卸载2007(扭转在其中安装的顺序),然​​后安装Excel 2003,然后安装Excel 2007,让你安装在正确的顺序两个版本。

Yes, this is 100% correct. You could try running a repair on Excel 2007, this would be the easiest thing to do. If this does not work, then I would uninstall both and then re-install them both. I would uninstall Excel 2003 and then uninstall 2007 (reversing the order in which you installed them) and then install Excel 2003 and then install Excel 2007 so that you are installing both versions in the correct order.

但请记住,做这个时,Excel 2007将被默认,当你调用运行 Excel.Application excelApp =新的应用程序()

But keep in mind that by doing this, Excel 2007 will be run by default when you call Excel.Application excelApp = new Application().

实际的建议做法是的的有开发人员的计算机上运行的Excel两个版本。欲了解更多关于这个,请参阅:

The actual recommended practice is not to have both versions of Excel running on the developer's machine. For more on this, see:





  • Why is VS development not supported with multiple versions of Office?
  • Can you build one add-in for multiple versions of Office?
  • Writing Automation clients for multiple Office versions

我曾经对我的同一个开发多个版本的Excel机了,我个人觉得缺点并不复杂,因为这些条款使之声。一般情况下,Excel 2007中PIA是向后兼容到Excel 2003 PIA,一切工作正常。但我一旦陷入类似你们注册表混乱,决定做正确的事。我卸载这两个,然后只重新安装Excel 2007中。

I used to have multiple versions of Excel on my same development machine, and I personally felt that the downsides were not as complicated as these articles make it sound. In general, the Excel 2007 PIA is backward-compatible to the Excel 2003 PIA and everything works fine. But I once got into a registry mess similar to yours and decided to "do the right thing". I uninstalled both and then only re-installed Excel 2007.

从那里我安装了虚拟PC,这是免费的(VM洁具实际上是好一点,但它不是免费的),然后安装我的下版本的Excel 2003年,2002年,2000年和97年在不同的虚拟机。这肯定是一些设置工作,但一旦你做到这一点,一切都是100%干净。

From there I installed Virtual PC, which is free (VM ware is actually a little better, but it's not free) and then installed my lower versions of Excel for 2003, 2002, 2000, and '97 on separate VMs. It is definitely some work to set up, but once you do this, everything is 100% clean.

这是说,我可能不会希望真正的发展的对VM上的Excel版本较低-,这将是太难使用Visual Studio在VM中主持。因此,这些虚拟机仅用于测试部署,以确保您的系统可以对各种客户端配置工作,不错。有意义吗?

That said, I probably would not want to actually develop against lower-versions of Excel on a VM, it would be too hard to use Visual Studio hosted within a VM. So these VMs are only good for testing deployment to make sure that your system can work against various client configurations. Make sense?

希望这有助于!

迈克

这篇关于试图做办公自动化与Excel 2007,但使用Excel 2003中不断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:04