vincent90152900

Thank you for replying

Re: Visual C# General How to get the sheet name from an excel file in c#.net?

Sonik1

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