支持不同版本的Office与Office自动化不同、版本、Office

2023-09-03 10:07:42 作者:太阳永远不懂向日葵的执着

我们创建一个使用Office 2007的应用程序(Excel 2007中)从Excel工作表中读取数据。然而。我注意到,当我要部署与Office 2003安装在系统上的应用程序,它崩溃,因为其他PIA的(和其他DLL)的需要为这个版本的Office引用。

We created an application that uses Office 2007 (Excel 2007) to read in data from an Excel worksheet. However. I noticed that when I want to deploy the application on a system with Office 2003 installed, it crashes because other PIA's (and other dll's) need to be referenced for this version of office.

我是否需要编写不同版本的我的应用程序,以便能够支持不同版本的Office或者是有这个问题?

Do I need to compile different versions of my application to be able to support different versions of Office or is there a more elegant solution for this problem?

我使用Visual Studio 2010(C#)和.NET 4.0平台。

I use Visual Studio 2010 (C#) and the .Net 4.0 platform.

推荐答案

由于您使用的是.NET 4中,你可以使用嵌入式的PIA(又名无PIA)。在Office参考更改选项,这样嵌入互操作类型为真。

As you're using .NET 4, you can use "embedded" PIAs (aka "No PIA"). Change the option on the Office reference so that "Embed Interop Types" is True.

只要你只使用它们的计算机部署上支持的Office的功能,你应该罚款。

So long as you only use features of Office which are supported on the machine you deploy on, you should be fine.

这也意味着: - 您不必担心PIA本身不是目标机器上present - 这是 VARIANT 在原来的COM接口类型,现在重新使用presented 动态在code,它可以让你的生活更简单

It also means that: - You don't need to worry about the PIA itself not being present on the target machine - Any methods or properties which are of the VARIANT type in the original COM interface are now represented using dynamic in your code, which can make your life simpler

 
精彩推荐