Last post Feb 26, 2019 09:59 AM by Leon Davis
Feb 25, 2019 03:25 PM|GeorgeN|LINK
I'm fairly new to ASP.NET (MVC) and I wanted to parse a file, specifically a .xlsx. Now, because I am a newbie, I used a csv as a test but I don't know how to handle it.
What I want to do is simply import a file with .xlsx extension via a view page, parse it row-by-row using my page's controller, validate that there is no other value with the same "category" and then upload it to my Microsoft Database.
This is what I've written so far.
So what do you think? Can someone help me modify it or point me to a book where I can find an example similar to it?
Feb 26, 2019 08:23 AM|Yuki Tao|LINK
Since there are some PHP code,I can't reproduce your issue.
According to your code,I suggest you could find a third party library to read and parse the content of Excel sheets.
The list is given below of the reference libraries
1.Install NuGet package LinqToExce:
2.Install NuGet package EPPlus:
3.Using OLEDB library and the read data will be inserted into SQL Server database table using SqlBulkCopy:
Feb 26, 2019 09:59 AM|Leon Davis|LINK
The following method for your reference:
1. Seach Spire.XLS and install it from nuget.
2. Convert excel to datatable
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;
DataTable dt = sheet.ExportDataTable();
3. Then it's easy to insert datatable to database.