DEV Community

Cover image for Finally found a cross-platform Excel parsing library
João Antunes
João Antunes

Posted on • Originally published at blog.codingmilitia.com on

Finally found a cross-platform Excel parsing library

Intro

I know, I know, I’ve been living under a rock! The ExcelDataReader library has been there forever, but only recently I’ve came across it. What sets it apart from the others I’ve found along the way is being cross-platform and not being required to install some weird external dependencies.

Getting started

To get started with the library we just need to add the desired NuGet package(s).

  • dotnet add package ExcelDataReader for the base package with lower level APIs
  • dotnet add package ExcelDataReader.DataSet for some extensions that make it simpler to use
  • dotnet add package System.Text.Encoding.CodePages, required when running in .NET Core only, due to (taken from the projects GitHub page) “This is required to parse strings in binary BIFF2-5 Excel documents encoded with DOS-era code pages. These encodings are registered by default in the full .NET Framework, but not on .NET Core.”

The code

The code is really simple, at least for my use case, as I don’t need anything too fancy. In the project I originally used it, we just needed to read some tables from Excel files provided to us with the expected results of some business logic, and assert our implementation correctness in the tests. This sample is derived from our simple requirements.

I’d say the code is pretty simple and doesn’t need much explanation. The only thing maybe worth pointing out is the System.Text.Encoding.RegisterProvider method call, which is related to what I mentioned previously regarding the need for the System.Text.Encoding.CodePages package.

Outro

So, if you have been living under a rock like me and require a simple to use library for reading some Excel files, I’d say this is a very good option.

Not that it’s needed for this so simple sample, but the entire sample project is here.

Thanks for stopping by, cyaz!

Top comments (5)

Collapse
 
jeikabu profile image
jeikabu

Will have to check this out. I can't remember what we're using, I just know that I can't build it on OSX...

Collapse
 
joaofbantunes profile image
João Antunes

This one I tested in MacOS and in a Docker container just to be on the safe side 🙂

Collapse
 
tiagodenoronha profile image
Tiago de Noronha

Thanks for the find!

Collapse
 
praneetnadkar profile image
Praneet Nadkar

Thanks for the post. Good one!
I am curious, Open XML SDK does serve the same purpose, doesn't it?

Collapse
 
joaofbantunes profile image
João Antunes

Hi Prannet!
I didn't try that one, maybe because I always looked just for Excel and not the open format.
From what I'm reading about it, it seems to be able to do the same and even more, so thank you for drawing my attention to it.
If this works cross-platform without weird external dependencies (most libraries I found didn't) it's another (maybe better) option.