Limey
Limey

Reputation: 2772

Microsoft.ACE.OLEDB.12.0 Get worksheet name

I have been looking for a way to get the first worksheet name in a spreadsheet that I have uploaded.

Now, I have found many flavors or code when it comes to using Jet 4, but I have to use Ace 12, and when I use that driver, it will never get anything about the spreadsheet. Does anyone know a good way to pull the spreadsheet name with Ace 12?

Upvotes: 5

Views: 4632

Answers (1)

shf301
shf301

Reputation: 31394

Since all of the worksheet's are listed as table names you can use the OleDbConnection.GetOleDbSchemaTable() method to get a list of all worksheets in the file. I'm not sure about the order they are returned in, but I'd expect that they are in worksheet order.

DataTable dt = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string workSheetName = (string)dt.Rows[0]["TABLE_NAME"];

Upvotes: 13

Related Questions