NPOI实现Excel导入
Posted Jus
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; }
以上是关于NPOI实现Excel导入的主要内容,如果未能解决你的问题,请参考以下文章
c#使用NPOI进行Excel导入导出,附源码,vs2010