string strExtName = Path.GetExtension(strFilePath); if (strExtName.Equals(".xls") || strExtName.Equals(".xlsx")) { using (FileStream file = new FileStream(strFilePath, FileMode.Open, FileAccess.Read)) { ISheet sheet = null; if (strExtName.Equals(".xls")) { HSSFWorkbook workbook = new HSSFWorkbook(file); sheet = workbook.GetSheetAt(iSheetIndex); } if (strExtName.Equals(".xlsx")) { XSSFWorkbook workbook = new XSSFWorkbook(file); sheet = workbook.GetSheetAt(iSheetIndex); } } }
说明: strFilePath是文件全路径; 使用的 NPOI 版本是 2.1.3.1
时间: 2024-11-05 18:38:23