Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 372
Chris Avatar asked Jun 21 '11 20:06

Chris


People also ask

Can you have multiple versions of Office?

You can install and use more than one version of Office on a single computer. For example, you can install and use both Office 2013 and Office 2010 on the same computer.

What are the different version of Office?

Four major versions of Office 2019 for Windows and 2 for Mac OS were released for Office 2019: Home & Student for PC/MAC: Includes core applications only. Home & Business for PC/MAC: Includes core applications plus Outlook. Professional: Includes core applications plus Outlook, Publisher and Access.

Can you run Office 2007 and Office 365 on the same computer?

Yes, you can run both on the same computer (I have that setup currently on my machine). Your current problem is with "Windows File Associations", it is not actually an Office problem. There is a simple fix, do an Office Repair of your Office 365 installation. That should reset the file associations as you wish.

How does Microsoft Office help in the automation of an Office?

Automation of Microsoft WordMake a document that can import information from other systems, such as databases, Excel workbooks, etc. Create worksheets that can validate themselves before saving. Automate documents so that when you save them, they will save their information into a database.


1 Answers

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

like image 160
Jon Skeet Avatar answered Oct 13 '22 11:10

Jon Skeet