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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With