Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Excel Sheet Names In the Correct Order 1

Status
Not open for further replies.

mbde

Programmer
Mar 14, 2005
55
US
Here is my code for getting Sheet Names

DataTable dataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

if(dataTable != null)
{
excelSheets = new String[dataTable.Rows.Count];

for(int i = 0; i < dataTable.Rows.Count; i++)
{
excelSheets = dataTable.Rows["TABLE_NAME"].ToString();
}
}

Later on I filter out the ones with just a $. This code works 90% of the time but for some excel files, the sheet names seem to come in a strange order. It is not the order they appear in or the order they were created which is key to my project. Does anyone know why this happens? Also does anyone know of a way to get the Sheet index instead of the Table Name?
 
GetOleDbSchemaTable returns a number of columns, one of which is DATE_CREATED. If you apply a DataView to the resulting DataTable you can apply a sort on this column.
 
Thank you,
I did see a date created but then I started wondering how do I get the name and the date into one array/Hashtable and then get in the correct sort order and so on. My head was spinning, but I (often) forget about data views.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top