tags:

views:

55

answers:

2

when adding a reference I see:

.net tab

microsoft.office.tools.excel

is that the one I need to read a excel file?

other posts seem to be using a COM assembly with 'interop' in it?

+1  A: 

The Interop one is available on the COM tab if you have Excel installed. It will be "Microsoft Excel 12.0 Object Library" or similar. The version number represents the version of Office so make sure you get the one you're after, though Office should be backwards compatible if you select an older one.

This will give you a reference under the references folder of: Microsoft.Office.Interop.Excel

Ian
what would my ADO.NET connection string use then? Microsoft.Jet.Oledb.4.0 ?
mrblah
If you're using OleDB I don't think you need a reference to Excel at all? I believe it just works on datasets. If you check out http://www.connectionstrings.com they suggest things like {Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";} for an Excel 2007 file.
Ian
Generally you would use COM and the Interop when you want to directly open up Excel and read the values straight out from Cells or Rows etc.
Ian
A: 

Microsoft.Office.Tools.Excel is part of Visual Studio Tools for Office. This is a Managed wrapper around Office applications so you can extend them using C# but only works with Office 2003 upwards.

Microsoft.Office.Interop.Excel is a direct COM interop assembly which provides access to the entire Excel Automation model through the COM interface.

The first option is probably the easiest to use but I don't think it contains all the functionality of the second.

Another option would be to open the Excel file using ADO.NET cia the JET datasource. This would mean querying the sheet as though each worksheet was a database table rather than accessing through the normal Row/Cell object model.

Iain