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

I am working on a VS 2008 C # program that should receive data from an Excel spreadsheet. The problem is that users are running a combination of Office 2007 and Office 2010. Therefore, I am trying to get some pointers in the right direction to programmatically retrieve data from xls that do not care about which version of the office the user has installed.

Bonus points if they are compiled in both environments (VS2008 / Office2007 and VS2008 / Office2010)

+3
source share
6 answers

You can use OleDB .

, OleDbConnectionStringBuilder, :

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());  
+6

, , ...

SpreadsheetGear, . , , excel. SpreadsheetGear excel, excel.

+1

. Excel .Net. , - .

codeplex.com , : Excel Data Reader

0
source

If you really want to use Excel to read data, you should refer to the lowest version of Excel that you expect from your users. Excel 2010 is backward compatible with Excel 2007 and should support applications written against the 2007 library.

0
source

Just export the data to a csv or txt file and it will be irrelevant.

0
source

This one is free and easy to use.

http://npoi.codeplex.com/

0
source

Source: https://habr.com/ru/post/1767250/


All Articles