Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.ACE.OLEDB.12.0 Get worksheet name

Tags:

c#

asp.net

excel

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?

like image 878
Limey Avatar asked Aug 02 '12 17:08

Limey


1 Answers

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"];
like image 102
shf301 Avatar answered Nov 14 '22 21:11

shf301