I know that there are different ways to read an Excel file:
Iterop
Oledb
Open Xml SDK
Compatibility is not a question because the program will be executed in a controlled environment.
My Requirement :
Read a file to a DataTable
/ CUstom Entitie
s (I don't know how to make dynamic properties/fields to an object[column names will be variating in an Excel file])
Use DataTable/Custom Entities
to perform some operations using its data.
Update DataTable
with the results of the operations
Write it back to excel file
.
Which would be simpler.
Also if possible advice me on custom Entities (adding properties/fields to an object dynamically)
If you can restrict it to just (Open Office XML format) *.xlsx files, then probably the most popular library would be EPPLus.
Bonus is, there are no other dependencies. Just install using nuget:
Take a look at Linq-to-Excel. It's pretty neat.
It also allows for strongly-typed row access too.
Try to use this free way to this, https://freenetexcel.codeplex.com
Using OLE Query, it's quite simple (e.g. sheetName is Sheet1$):
For newer Excel versions:
You can also use Excel Data Reader an open source project on CodePlex. Its works really well to export data from Excel sheets.
The sample code given on the link specified:
Reference: How do I import from Excel to a DataSet using Microsoft.Office.Interop.Excel?