Load excel data on the screen [closed]

0

I have a problem loading data from a worksheet on the table.

The system is done in C # MVC5 with razor and entity framework, I need the user to choose an already filled excel file and with the data of that file I have to present it in a html table (table), after that the user will check the loaded data, assuming it has checked the data and are in order, it will click on a button to insert it into the database.

That is, I will have to read the line on the table to make the insert.

So far I've only been able to save the worksheet to a directory.

Someone like doing this in MVC?

    
asked by anonymous 28.07.2017 / 21:25

1 answer

2

If you need to extract information from an Excel I suggest you take a look at the link library. It has manipulations for Excel, both to extract data and to generate.

If you want to generate: link

If you want to read:

   byte[] file = File.ReadAllBytes("Caminho do seu arquivo Arquivo");
    MemoryStream ms = new MemoryStream(file);
    using (var package = new ExcelPackage(ms))
    {
        //Obtendo a Planilha
        var workBook = package.Workbook;
        if (workBook != null)
        {
            //Verifica se Existe alguma Planilha
            if (workBook.Worksheets.Count > 0)
            {
                // Se Existe pega a primeira
                var currentWorksheet = workBook.Worksheets.First();

                //Leitura das Linhas
                for (int j = currentWorksheet.Dimension.Start.Row + 1;
                            j <= currentWorksheet.Dimension.End.Row;
                            j++)
                {
                    orcamento = new OrcamentoBO();
                    orcamento.Linha = j.ToString();
                    //Leitura das Colunas/Celulas
                    for (int i = currentWorksheet.Dimension.Start.Column; i <= currentWorksheet.Dimension.End.Column; i++)
                    {
                        var celula = currentWorksheet.Cells[j, i].Value;

                        if (celula != null)
                        {
                           //sua logica aqui
                        }


                    }


                }

            }
        }
    }
    
01.08.2017 / 20:37