Best way to parse a Excel spreadsheet with C#?

Posted on 2008-11-18
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
    LVL 4

    Expert Comment

    LVL 4

    Expert Comment

    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 29

    Expert Comment

    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

    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?
    LVL 4

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now