Reading excel spread sheet as strongly typed objects
Recently, I was working on a prototype application that required data to be read from many different Excel spreadsheets (both xls and xlsx versions) each containing a large number of worksheets. I started with the usual way of creating one DTO (Data Transfer Object) for each worksheet and then pulling the data from Excel through OleDBReader. It became repetitive to do the same thing over and over for every single worksheet. After quick thought, I decided to write a simple tool that can solve this problem of data access (as I didn’t want to spend a lot of time just building the infrastructure) .
The end result is a tool that can generate an assembly containing Strongly Typed DTO’s by querying the excel (as I didn’t want to create them manually) that can then be included as a reference in our project and a library that provides methods to query the excel data through a single repository class. By abstracting out the DTO generation and accessing data from excel, I can now concentrate on building the prototype application that can deliver some business value.
Code for this is available on Git Hub: https://github.com/mvba/ExcelMapper
Download the BuildDTOsFromExcel.exe and ExcelMapper.dll with an example usage here.
You can read a brief description on how to use ExcelMapper here
We can definitely improve this tool further, but it works if you are looking for a quick solution to query the excel sheets. If you are interested in improving this tool, please feel free to comment.