补充:本文链接:https://blog.csdn.net/ethan_10/article/details/80335350
读取excel
IWorkbook workBook = null;
using (Stream stream = files[0].OpenReadStream())
{
if (fileName.EndsWith(".xlsx"))
{
//2007版本
workBook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
else if (fileName.EndsWith(".xls"))
{
//2003版本
workBook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
}
if (workBook == null)
{
throw new UserFriendlyException(@"读取Excel失败,WorkBook为空");
}
获取excel中的某一页
ISheet sheet1 = workBook.GetSheetAt(0);//获取第一页
获取第一行第一列的数据
string firstRow = sheet1.GetRow(0).GetCell(0).StringCellValue.Trim();