conrad2010
asked on
C# ADO.NET get all tab names in Excel spreadsheet
I am trying to get all the tab names that have data from an Excel spreadsheet.
Somewhere I found this code and want to adapt it to loop through all tabs (worksheets) and store it in a drop down combobox:
OleDbConnection dbConnection = new OleDbConnection (@"Provider=Microsoft.Jet. OLEDB.4.0; Data Source=C:\SAMPLE.XLS;Exten ded Properties=""Excel 8.0;HDR=Yes;""");
dbConnection.Open ();
try
{
// Get the name of the first worksheet:
DataTable dbSchema = dbConnection.GetOleDbSchem aTable (OleDbSchemaGuid.Tables, null);
if (dbSchema == null || dbSchema.Rows.Count < 1)
{
throw new Exception ("Error: Could not determine the name of the first worksheet.");
}
string SheetNameOne = dbSchema.Rows [0] ["TABLE_NAME"].ToString ();
}
finally
{
dbConnection.Close ();
}
Somewhere I found this code and want to adapt it to loop through all tabs (worksheets) and store it in a drop down combobox:
OleDbConnection dbConnection = new OleDbConnection (@"Provider=Microsoft.Jet.
dbConnection.Open ();
try
{
// Get the name of the first worksheet:
DataTable dbSchema = dbConnection.GetOleDbSchem
if (dbSchema == null || dbSchema.Rows.Count < 1)
{
throw new Exception ("Error: Could not determine the name of the first worksheet.");
}
string SheetNameOne = dbSchema.Rows [0] ["TABLE_NAME"].ToString ();
}
finally
{
dbConnection.Close ();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.