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

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

  • Thursday, May 31, 2007 3:51 AM
     
     
    Thank you for replying

All Replies

  • Thursday, May 31, 2007 5:09 AM
     
     Answered

    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

  • Sunday, January 15, 2012 8:48 PM
     
     
    Thank you Sonik for taking the time for this post. It helped me out.