Best way to parse a Excel spreadsheet with C#?

Posted on 2008-11-18
Medium Priority
Last Modified: 2013-11-08
I've been using Microsoft.Jet.OLEDB.4.0 to parse spreadsheets for a while with no problems but i recently ran into an issue that will no longer allow me to use this method.  What is the best way to parse an Excel (NOT a csv) using .NET?  I am using Visual Studio 2008.
Question by:abemiester
  • 3

Expert Comment

ID: 22988575
1 thing to note:
In the 1st link they only mention retrieving a String value from one of the cells.  If it's a number you want, you'll need to cast value2, so

Console.WriteLine(excelCell2.Cells.Value2.ToString()); //Print the value of the cell for a single cell selection

becomes something like:

double val = (double)excelCell2.Cells.Value2
LVL 30

Expert Comment

ID: 22988656
If you have tables in Excel and need to work with the data probably the best way is to load the data into a dataset.
I used this quite often.

Have a look:

Quite many links of this sort.

Author Comment

ID: 22989921
Hey Shannon,
I tried that first link but VS is unable to find Excel.ApplicationClass().  Have you successfully tried this your self?  If so which version of the COM assembly for Excel did you include?

Accepted Solution

ShannonE earned 1500 total points
ID: 22990163
I'm using the "Microsoft Excel 11.0 Object Library"

Also, make sure to add:

using Excel = Microsoft.Office.Interop.Excel;

to the section with your using directives

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question