Read from Excel

  • Thread starter Thread starter Tommy Malone
  • Start date Start date
T

Tommy Malone

Would someone mind please posting sample code for reading data from a column
in Excel? And/or providing any recommended reading on the subject?

Thanks!
 
If you want something simple you can also use OledDBConnection of ADO.NET to connect to excel workbook as datasource. Use DataReader or DataSet to iterate through rows. You will need a valid connection string:

"provider=Microsoft.Jet.OLEDB.4.0;data source=c:\FileNam.xls;Extended Properties=Excel 5.0;"

Then just open connection and you can pretty much treat excel as any other datasource for simple queries of course.

Also use this SQL to select your column from Sheet1:
select ColumnName from [Sheet1$]
 
Thank you all. Great articles and examples. I feel stupid for asking after
seeing how easy it is.

Thanks again.

Lenn said:
If you want something simple you can also use OledDBConnection of ADO.NET
to connect to excel workbook as datasource. Use DataReader or DataSet to
iterate through rows. You will need a valid connection string:
"provider=Microsoft.Jet.OLEDB.4.0;data source=c:\FileNam.xls;Extended Properties=Excel 5.0;"

Then just open connection and you can pretty much treat excel as any other
datasource for simple queries of course.
Also use this SQL to select your column from Sheet1:
select ColumnName from [Sheet1$]

Tommy Malone said:
Would someone mind please posting sample code for reading data from a column
in Excel? And/or providing any recommended reading on the subject?

Thanks!
 
Hi Tommy,

Not asking is stupid.
Thank you all. Great articles and examples. I feel stupid for asking after
seeing how easy it is.

Next time you can give these answers.

:-)

Cor
 
The only problem that I found and haven't figured out yet is that you need to know the name of the sheet.

Well ... Same arguement can be made about a databse table. You have to know its name to begin with. Yes, you can look it up in system tables, but you have to know what you're looking for.


Are building some kind of Excel data explorer application? Yes, you can use Excel.Application to get the names of all sheets in a workbook.
Also Sheet1 is a default name.
 
Back
Top