:::: MENU ::::

Reading Excel Files in WPF using EPPlus

If your application need to read data from excel files then EPPlus is an awesome open source library for that operation. EPPlus reads and writes Excel 2007+ files using the Open Office XML format (xlsx).

I will show how to use this with WPF application but you can use same approach with any other platform (like ASP.net, even with console app). Once you extract data you are boss then. 🙂

Steps:

  • Install EPPlus package from Nuget

  • Upload file(.xlsx) from your application

XAML

C#

Here i made extension method for extracting data and return it into Collection Format of User Type. You can make extension method completely generic but for simplicity i made it specific type i.e. of User type.

  • Perform Extraction

Extension Method:

Here first choose the sheet from available sheets from which you want to extract data. ExcelWorkSheet provides lots of option for various purpose (check that out) but here we used its Dimension property to find end row number up to which we are looping for getting data. And also we used Cells property for getting specific cell data. The reason we start looping from second row is because first row typically contains header of that column and we are skiping that and extracting exact data only but again you can extract all data as per your need.

Now we get data from excel file then feed it with DataGrid of XAML page and its done. Now you can view excel file data on DataGrid of your application. Once you get data then you can do anything with data.

Here is screenshot of extracted excel data in WPF.

More about EPPlus on codeplex.

That’s It. Happy Coding 🙂