NPOI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /// <summary> /// 上传本地服务器 /// </summary> /// <param name="environment"></param> /// <returns></returns> [HttpPost( "/UpLoadImageFiles2" )] public async Task<ResDto<IActionResult>> UpLoadImageFiles2([FromServices] IWebHostEnvironment environment) { List<TmpUrl> list = new List<TmpUrl>(); var files = Request.Form.Files; if (files[0] == null ) { return new ResDto<IActionResult>() { Code = 500, Msg = "未导入" }; ; } Stream stream = files[0].OpenReadStream(); HSSFWorkbook workbook = new HSSFWorkbook(stream); //创建工作薄,并读取文件流 HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt(0); //获取第一个sheet var tmpCount = sheet.LastRowNum; var equipmentParameter = myDbContext.EquipmentParameter.ToList(); for ( int i = 1; i <= tmpCount; i++) { HSSFRow row = (HSSFRow)sheet.GetRow(i); //根据下标获取行数据 EquipmentParameter parameter = new EquipmentParameter(); //Id = int.Parse(row.Cells[0].NumericCellValue.ToString()),//获取单元格内容 parameter.EquipmentCoding = row.Cells[1].NumericCellValue.ToString(); parameter.DeviceName = row.Cells[2].RichStringCellValue.ToString(); //获取单元格内容 parameter.DeviceType = row.Cells[3].RichStringCellValue.ToString(); parameter.EquipmentModel = row.Cells[4].RichStringCellValue.ToString(); //获取单元格内容 parameter.EquipmentBrand = row.Cells[5].RichStringCellValue.ToString(); parameter.EquipmentLocation = row.Cells[6].RichStringCellValue.ToString(); //获取单元格内容 parameter.EquipmentState = int .Parse(row.Cells[7].NumericCellValue.ToString()); parameter.MaintenanceDepartment = row.Cells[8].RichStringCellValue.ToString(); parameter.OriginalNumber = row.Cells[9].NumericCellValue.ToString(); parameter.UseDate = DateTime.Now; parameter.PurchaseDate = DateTime.Now; parameter.MaintenanceStartTime = DateTime.Now; await myDbContext.EquipmentParameter.AddRangeAsync(parameter); myDbContext.SaveChanges(); } return new ResDto<IActionResult>() { Code = 200, Msg = "已导入" }; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术