Load excel data on screen

Asked

Viewed 335 times

0

I’m having a problem loading data from a spreadsheet on the screen (table).

The system is done in C# MVC5 with Razor and Entity framework, I need the user to choose an excel file already filled and with the data of this file I have to present in an html table even (table), after that the user will check the data loaded, Assuming that it checked the data and are in order, it will click on a button to do the Insert in the database.

I mean, I’ll have to read line by line from table to do the Insert.

So far only managed to save the spreadsheet in a directory.

Someone how to do this on MVC?

  • Young lady, that’s not exactly how the site works. What kind of help do you need? What have you tried? How can we help you (specifically speaking).

  • Is your specific difficulty in opening the Excel file and extracting your information? If so, add this information to the question.

1 answer

2

If you need to extract the information from an Excel I suggest you take a look at the library https://www.nuget.org/packages/EPPlus/ . It has manipulations for Excel, both to extract data and to generate.

If you want to generate : https://github.com/TBertuzzi/EppPlus

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
                        }


                    }


                }

            }
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.