Drogo
Drogo

Reputation: 117

Office-agnostic way to access data in a .xls file?

I'm working on a VS 2008 C# program that needs to get data out of an excel spreadsheet. Problem is that the users run a mix of office 2007 and Office 2010. So I'm trying to get some pointers in the right direction on a way to programmatically get data out of the xls that doesn't care which version of office the user has installed.

Bonus points if it will compile in both environments (VS2008/Office2007 and VS2008/Office2010)

Upvotes: 3

Views: 234

Answers (6)

liya
liya

Reputation: 792

This one is free and easy to use.

http://npoi.codeplex.com/

Upvotes: 0

Lance Roberts
Lance Roberts

Reputation: 22840

Just export the data to a csv or txt file, and it will be version agnostic.

Upvotes: 0

Anthony
Anthony

Reputation: 744

Not sure if this is a project in which you have a budget to work with....

At our company, we have used SpreadsheetGear and it has been awesome to work with. If you've got the funds for it, it is a great tool to have at your disposal when it comes to working with excel files. SpreadsheetGear can help with any kind of excel file and it does not require the user to have excel installed.

Upvotes: 1

Rune Grimstad
Rune Grimstad

Reputation: 36340

If you really want to use Excel itself to read the data then you should reference the lowest version of Excel that you expect your users to have installed. Excel 2010 is backwards compatible with Excel 2007 and should support applications written against the 2007 library.

Upvotes: 0

Rune Grimstad
Rune Grimstad

Reputation: 36340

You don't have to use office automation at all. There are many packages for reading Excel files from .Net. Some are commercial and some are open source.

A random search at codeplex.com returned this one for instance: Excel Data Reader

Upvotes: 0

SLaks
SLaks

Reputation: 888223

You can use OleDB.

Note that their example is incorrect and needs to use an OleDbConnectionStringBuilder, like this:

OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();

if (isOpenXML)
    builder.Provider = "Microsoft.ACE.OLEDB.12.0";
else
    builder.Provider = "Microsoft.Jet.OLEDB.4.0";

builder.DataSource = fileName;
builder["Extended Properties"] = "Extended Properties=\"Excel 8.0;HDR=YES;\""

con = new OleDbConnection(builder.ToString());  

Upvotes: 6

Related Questions