获取Excel的sheet名称和数量

时间:2024-02-29 18:00:28
string name=sheet.Name; //获取该sheet的名称
   string amount=book.WorkSheets.Count.ToString(); //获取该book的sheet数量。
     string sSheetName=null;
     object missing = Missing.Value;
      OleDbConnection conn = new OleDbConnection();
      Excel.Application excelApp = new Excel.Application();
     excelApp.Application.Workbooks.Open(path, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value ,Missing.Value,Missing.Value,Missing.Value ,Missing.Value ,Missing.Value );
       for (int i = 0; i < excelApp.Workbooks[1].Worksheets.Count; i++)
        {
          Excel.Worksheet ws = (Excel.Worksheet)excelApp.Workbooks[1].Worksheets[1];
          sSheetName = ws.Name;
        }