.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Getting the sheet name of Excel at run time from the C# Win App

Posted By:Suderson Sarathy       Posted Date: November 22, 2010    Points: 15    Category: File Operation    URL: http://www.dotnetspark.com  

This article describes on how to get the sheet name on a single Excel file at run time in C3 win app

private string getSheetName()
  dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  String[] excelSheets = new String[dt.Rows.Count];
  int i = 0;
  foreach (DataRow row in dt.Rows)
    excelSheets[i] = row["TABLE_NAME"].ToString();
  if (excelSheets[0].Substring(0, 1).ToString() == "'")
    int len = excelSheets[0].Length;
    len = len - 2;
    return excelSheets[0].Substring(1, len);
   return dt.Rows[0]["TABLE_NAME"].ToString();
This describes on how to get the Excle sheet name at run time from C#.
The OleDbSchemaGuid.Tables will return values in the form of a table. If the Excel file has more than one sheet, then each sheet will be represente in rows


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend