Working with Excel data in C#

Asked

Viewed 1,591 times

5

I need to create an application that reads a small sequence of data available each in an Excel column. My question is whether the best way is to deal directly with SQL uploading the file and then dealing with a precedent or work with the data in C# and send it to each column of my SQL table.

Treating the side of C# I believe I can have more security in relation to what I am sending to the bank, I gave a read on this issue: https://stackoverflow.com/questions/657131/how-to-read-data-of-an-excel-file-using-c but I didn’t quite understand.

For the example of Procedure I am using this article as a basis: http://www.aspsnippets.com/Articles/How-to-Import-Excel-Sheet-data-into-SQL-Server-using-ASPNet.aspx

  • 2

    Look, I wouldn’t advise you to use SQL to do this. There are many ways to import Excel files, but this is to your liking. Take a look at Closed XML and Open XML.https://closedxml.codeplex.com/documentation

  • What exactly did you not understand from the other question?

  • I used part of the code of the answer chosen for that question: http://answall.com/questions/14034/erro-ao-ler-xml . It worked perfectly. I used XML because I was not able to read Excel on the server side.

1 answer

2


It is not advisable business rules in the database! Only for this reason ideally would you use C#.

I recommend the library: Linqtoexcel

You can read Excel files very intuitively:

var excel = new ExcelQueryFactory("excelFileName");
var indianaCompanies = from c in excel.Worksheet<Company>()
                       where c.State == "IN"
                       select c;

Browser other questions tagged

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