Today we are going to learn how to read Microsoft Excel documents. The complete source code has been shared for your easy reference.

First, you need to reference the 'Microsoft.Office.Interop.Excel.dll'. You can either get it from VSTO (Visual Studio Tools for Office) SDK, download from Microsoft server or install via NuGet.

Now, in your .NET app, create the instance of an Excel application. Then open the workbook, that you want to read, by calling the 'xlApp.Workbooks.Open' method as shown in the below code snippet. Next, you need to iterate through the sheets available in the workbook and find out the used range. It's the cells area where the data resides. Now iterate through this range for each sheet to find out the actual text content.

Was it helpful? Do let me know if you have any queries. Stay tuned for more updates.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

This kind of reading/writing Excel documents has some disadvantages:1.) You must have MS Office installed (which might mean that you have to buy an additional license)2.) If you don't handle your exceptions right, several invisible Excel instances are still running3.) You have to do memory management (releasing COM objects)4.) It's slow

Every single point from above can be eliminated with doing one thing different: Don't work with Excel itself -> work with the document. There is an Open Document Standard so there are several libraries that allow working directly with the document, e.g. Open XML SDK (https://github.com/OfficeDev/Open-XML-SDK). It's a lot (!!!) faster and you are not forced to have Excel installed.

This is a good fit for desktop automation where you'll already have office installed on the local machine. If you're building a server-side application I'd strongly recommend looking at the open source library called NPOI which handled both the old binary formats as well as the newer XML formats.

About Me

Kunal Chowdhury is a Windows Platform Development MVP of Microsoft, a Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.