none
How to get the sheet name from an excel file in c#.net?

Answers

  • In C# .net 2.0, you can get a reference of sheets of a excel file. Here is a small code snippet,

    Add reference of Microsoft.office.Interop.excel

     

    Excel.Application ExcelObj = new Excel.Application();

    Excel.Workbook theWorkbook = null;

    string strPath="MENTION PATH OF EXCEL FILE HERE";

    theWorkbook = ExcelObj.Workbooks.Open(strPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

    Excel.Sheets sheets = theWorkbook.Worksheets;

    Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);//Get the reference of second worksheet

    string strWorksheetName = worksheet.Name;//Get the name of worksheet.

     

     

    Sonik

    Thursday, May 31, 2007 5:09 AM

All replies

  • In C# .net 2.0, you can get a reference of sheets of a excel file. Here is a small code snippet,

    Add reference of Microsoft.office.Interop.excel

     

    Excel.Application ExcelObj = new Excel.Application();

    Excel.Workbook theWorkbook = null;

    string strPath="MENTION PATH OF EXCEL FILE HERE";

    theWorkbook = ExcelObj.Workbooks.Open(strPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

    Excel.Sheets sheets = theWorkbook.Worksheets;

    Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);//Get the reference of second worksheet

    string strWorksheetName = worksheet.Name;//Get the name of worksheet.

     

     

    Sonik

    Thursday, May 31, 2007 5:09 AM
  • Thank you Sonik for taking the time for this post. It helped me out.
    Sunday, January 15, 2012 8:48 PM
  • Thanks!!!
    Friday, June 28, 2013 4:15 AM