Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to read sheet name from Excel sheet


C#
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);

         for (int i = 0; i < dtExcelSchema.Rows.Count; i++)
         {
             drpsheet.DataSource=dtExcelSchema.Rows[i]["Table_Name"].ToString().Replace("$","");
         }

         //TableName.Rows[0]["ColumnName"].ToString();
         drpsheet.DataBind();
Posted

I remember an old post a while ago where the guy used a string array to get all sheets.
Not hundred percent sure but off the bat i would say something like this.
Havent tested code but sheet names should be added to the array.

int i = 0;
String[] xSheets = new String[dtExcelSchema.rows.count];

foreach(DataRow row in dt.Rows)
{
xSheets[i] = row["tablename"].ToString();
i++;
}
 
Share this answer
 
Hi,

See the following code. It might be help you.
C#
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
          "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
        objConn = new OleDbConnection(connString);
        objConn.Open();
        
        dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

        if(dt == null)
        {
           return null;
        }

        String[] excelSheets = new String[dt.Rows.Count];
        int i = 0;
        
        foreach(DataRow row in dt.Rows)
        {
           excelSheets[i] = row["TABLE_NAME"].ToString();
           i++;
        }


Thnaks,
Viprat
 
Share this answer
 
C#
 Microsoft.Office.Interop.Excel.ApplicationClass excelObj = new  Microsoft.Office.Interop.Excel.ApplicationClass();
 Microsoft.Office.Interop.Excel.Workbook workBookObj = null;
 workBookObj = excelObj.Workbooks.Open(fileName, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in workBookObj.Sheets)
{
 sheet.Name
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900