• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1170
  • Last Modified:

Best way to parse a Excel spreadsheet with C#?

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.
0
abemiester
Asked:
abemiester
  • 3
1 Solution
 
ShannonECommented:
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
0
 
anarki_jimbelCommented:
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:
http://www.codeproject.com/KB/dotnet/ExportExcelData.aspx

Quite many links of this sort.
0
 
abemiesterAuthor Commented:
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?
0
 
ShannonECommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now