I am trying to load an Excel 97 single tabbed spreadsheet into a SQL server table using the OleDbDataAdapter function. From all the documentation I have found, the first parameter should be “select * from [sheet1$]”. This works fine for me only if the tab in the worksheet is named Sheet1. If I change what’s in the [] brackets to the actual tab name, it also works fine.
The issue is that the spreadsheet being loaded is coming from another system and that system changes the tab name with each load. How can a figure out what the tab name is so that my users don’t have to open the spreadsheet and rename the tab?
Ok, first, open an OleDB connection to your Excel spreadsheet.
Then, use something like the following (shown in VB.NET):
This will loop through all of the tables in the Excel file (table = sheets or named ranges) and get the name of each. In addition, it will filter out any tables that have characters in them that can’t be accessed via ODBC (spaces are the most common issue).