You could use Excel automation objects. The function below shows how you can get the name of the first sheet.
Some notes:
- There's a problem, you need to have Excel installed on the server that'll run this code.

- Add the reference to the Excel API in your project.
- I don't remember if Workboos.Worksheets is a zero-based index or one-based . If get_Item(1) gets the second sheet, use 0.
public string GetWorkSheetName(string FileName) { Excel.Application excelApp = new Excel.ApplicationClass(); Excel.WorkbookClass wb = (Excel.WorkbookClass) excelApp.Workbooks.Open( FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); Excel.Worksheet ws = (Excel.Worksheet) wb.Worksheets.get_Item(1); string sName= ws.Name; wb.Close(); excelApp.Quit(); return sName; }
|