NPOI实现Excel导入
导入功能实现: var file = HttpContext.Current.Request.Files[0]; GetExtensionsFromFileStream(file.InputStream); using NPOI.XSSF.UserModel; public List<MaterialExtend> GetExtensionsFromFileStream(Stream excelFielStream) { var list = new List<DBOMS_MaterialExtend>(); var book = new XSSFWorkbook(excelFielStream); var firstSheet = book.GetSheetAt(0); var ExtendType = firstSheet.SheetName; for (int i = 1; i <= firstSheet.LastRowNum; i++) { var entity = new DBOMS_MaterialExtend(); XSSFRow row = firstSheet.GetRow(i) as XSSFRow; entity.MaterialCode = (row.GetCell(0) as XSSFCell).StringCellValue; entity.ReferFactory = (row.GetCell(1) as XSSFCell).StringCellValue; entity.ExtendType = (int)Enum.Parse(typeof(ExtendTypeEnum), ExtendType, true); list.Add(entity); } return list; }