0

I am getting sheets names sorting alphabetically by next code.

        OleDbConnection connection = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=\"Excel 8.0;HDR=No;\"", filePath));
        OleDbCommand command = new OleDbCommand();
        DataTable tableOfData = null;
        command.Connection = connection;
        try
        {
            connection.Open();
            tableOfData = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string tablename = tableOfData.Rows[0]["TABLE_NAME"].ToString();
            tableOfData = new DataTable();
            command.CommandText = "Select * FROM [" + tablename + "]";
            tableOfData.Load(command.ExecuteReader());
        }
        catch (Exception ex)
        {
        }

I want only to read them with original order. Any idea?

Aya Aboud
  • 371
  • 2
  • 4
  • 16

1 Answers1

0

After many search i found out that "OLEDB" not support reading sheets in original order (read sheets names in alphabetical order only) but there are many way support reading sheets names in original order from excel file.

Helped link: Reading sheets in original order from excel file,
OLEDB does not preserve the sheet order as they were in Excel.

Community
  • 1
  • 1
Aya Aboud
  • 371
  • 2
  • 4
  • 16