Kira
Kira

Reputation: 1207

Using Office.Interop.Excel on machines where MS Office isn't installed

I have an application that uses Microsoft.Office.Interop.Excel, when I deploy it on machines where there isn't any version of MS Office I get the following error

enter image description here

I tried installing VSTOR as indicated in this so answer COM object with CLSID {00024500-0000-0000-C000-000000000046} is either not valid or not registered but this didn't solve the issue.

Upvotes: 1

Views: 2775

Answers (3)

Eugene Astafiev
Eugene Astafiev

Reputation: 49397

If you need to work only with open XML documents (*.xslx) you may consider using the Open XML SDK. See Welcome to the Open XML SDK 2.5 for Office for more information.

In case of binary file format you need to use any third-party components that don't required Office/Excel installed on the machine.

Pay special attention to the following fact:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

Upvotes: 4

Alex
Alex

Reputation: 21766

You can't use Microsoft Interop libraries if MS Office is not installed. You might want to look at alternative options to read Excel or Word files. There are many free and (paid) C# libraries you could use for this purpose, for example:

https://exceldatareader.codeplex.com/

https://github.com/ExcelDataReader/ExcelDataReader

Upvotes: 2

GRUNGER
GRUNGER

Reputation: 496

You need download and install Microsoft Office {year}: Primary Interop Assemblies - it's free.

Upvotes: 0

Related Questions