Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Microsoft.Office.Interop.Excel Availability

Tags:

c#

.net-4.0

I am working on an application that can import data from several different formats. I would like to include CSV and other flat-file types (easy) as well as XLS and XLSX.
It looks like my best option is to use Interop.Excel which I understand is only available if Excel is installed.
Is there a way to check whether Interop.Excel is available and tell the user that Excel must be installed to import from XLS/XLSX?

like image 516
yakatz Avatar asked Feb 07 '12 22:02

yakatz


2 Answers

Microsoft.Office.Interop.Excel is an Office Primary Interop Assembly that you could ship with your application no matter whether the client has Office installed or not. It won't do any harm until you start using it. So before using it you could look at the registry to see if Office is installed.

like image 139
Darin Dimitrov Avatar answered Oct 26 '22 11:10

Darin Dimitrov


If you want to support native Microsoft Excel files and do not want to take a dependancy on Microsoft Excel, then look into OpenXML. This will only work with the newer Excel XML formated files. If your needs are simple and you just need to read data out of the legacy formated Excel file or CSV file you may be able to use the Ace provider and/or Microsoft Jet OLE DB 4.0 providers

OpenXML allows you to read/write to new XML formated Excel files. There are several threads on StackOverflow with more info on using OpenXML that are worth checking out.

like image 38
codechurn Avatar answered Oct 26 '22 10:10

codechurn