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 = "已导入" };
        }

  

posted @   电器小君子  阅读(81)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示