var ext = Path.GetExtension(filename).ToLower(); using (FileStream fs = File.OpenRead(filename)) { IWorkbook wk; if (ext.Contains("xlsx")) wk = new XSSFWorkbook(fs); else wk = new HSSFWorkbook(fs); ISheet sheet = wk.GetSheetAt(0); for (int j = 0; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row == null) return; ICell cell = row.GetCell(0); //当前表格 if (cell == null) return; } }