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