0

I'm getting an error when trying to run my code, it's reading the excel lines, but at the end of reading all the lines it's giving the error below.

My controller:

       [HttpPost]
       public IActionResult MostrarDados([FromForm] IFormFile ArquivoExcel)
       {
           Stream stream = ArquivoExcel.OpenReadStream();

           IWorkbook MeuExcel = null;

           if (Path.GetExtension(ArquivoExcel.FileName) == ".xlsx")
           {
               MeuExcel = new XSSFWorkbook(stream);
           }
           else
           {
               MeuExcel = new HSSFWorkbook(stream);
           }

           ISheet FolhaExcel = MeuExcel.GetSheetAt(0);

           int QtdFilas = FolhaExcel.LastRowNum;

           List<VMProduct> list = new List<VMProduct>();

           for (int i = 1; i <= QtdFilas; i++)
           {
               IRow fila = FolhaExcel.GetRow(i);

               list.Add(new VMProduct
               {
                   Id_Item = fila.GetCell(0).ToString(),
                   Nome_Item = fila.GetCell(1).ToString(),
                   Qtd_Estoque = fila.GetCell(2).ToString(),
                   Preco_por = fila.GetCell(3).ToString(),
               });
           }

           return StatusCode(StatusCodes.Status200OK, list);
       }
   }
}

Error:

Error

0 Answers0