//文件验证
HttpPostedFile file = HttpContext.Current.Request.Files[0];
if (string.Empty.Equals(file.FileName) || (file.FileName.IndexOf(".xlsx") <= 0 && file.FileName.IndexOf(".xls") <= 0))
{
return BadRequest("文件格式不正确!!!");
}
IWorkbook workbook = null;
if (file.FileName.IndexOf(".xlsx") > 0) // 2007版本
workbook = new XSSFWorkbook(file.InputStream);
else if (file.FileName.IndexOf(".xls") > 0) // 2003版本
workbook = new HSSFWorkbook(file.InputStream);
ISheet sheet = workbook.GetSheetAt(0);
C# Excel导入,判断文件版本
最新推荐文章于 2023-03-08 10:48:15 发布