Read excel file without worksheet name
Thursday, August 20th, 2009 | Author: admin
A few times we need to load data from Excel file but we don’t know the name of the worksheet.
There are many ways to do, but i like this one because don’t need to instantiating an Excel object.
C# code:
String conString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\temp\ExcelFile.xls;Extended Properties=Excel 8.0;";
OleDbConnection yourConnection = new OleDbConnection(conString);
try
{
yourConnection.Open();
DataTable sheetTable = yourConnection.GetSchema("Tables"); //get all tables
DataRow rowSheetName = sheetTable.Rows[0];
String sheetName = rowSheetName[2].ToString();
yourConnection.Close();
}
catch (Exception ex)
{
}
Enjoy ![]()
Category: Uncategorized
| | Leave a Comment


Recent Comments