简体   繁体   中英

support different Office versions with Office Automation

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.

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?

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

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.

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

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

Depending on whether you have any other requirements (you say reading data from excel), you can use the OLEDB driver to connect to the excel file and query it in a SQL manner.

Example: http://codehill.com/2009/01/reading-excel-2003-and-2007-files-using-oledb/

您可以参考PIA的多个版本的办公室,并在运行时找出从哪个路由您的电话。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM