athos
athos

Reputation: 6425

C++ using adodb to read excel file in 64-bit windows 7?

I've a legacy c++ code using adodb to read excel file in 32-bit windows, it's running file and it's something like:

#import "C:/Program Files/Common Files/System/ado/msado15.dll"  rename("EOF", "adoEOF") rename("BOF", "adoBOF")

string conn_str;
if(*(file_name.back()) == 'x')
    conn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file_name + ";Extended Properties=\"Excel 12.0 Xml;HDR=Yes;IMEX=1\"";
else
    conn_str = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + file_name + ";Extended Properties=\"Excel 8.0;HDR=Yes\"";

::CoInitialize(NULL);

pRec->Open("SELECT * FROM [" + SheetName + "]", conn_str, adOpenStatic, adLockOptimistic, adCmdText));

Now moving to the new environment to deploy (64-bit windows + 64-bit excel), the code cannot run, error message is "the Provider could not be found".

Trying to solve the issue, but after searching on Internet I'm a bit confused.

Microsoft FAQ About Windows DAC/MDAC etc seem say, "Microsoft Data Access Components (MDAC)" includes ADO, OLE DB, and ODBC; but MDAC is obsolete, and now the package is called "Windows Data Access Components (Windows DAC)" which is automatically installed in windows 7.

-- So I don't need to install MDAC on 64-bit Windows 7, and the download on Microsoft Data Access Components (MDAC) 2.8 SP1 is a 32-bit one?

But then how could I use the legacy code calling msado15.dll to read excel?

Shall I install the 32-bit MDAC to SysWOW64 folder and continue use it? But can this 32-bit msado open an excel file created by 64-bit excel?

Or shall I use some other dll from "Windows DAC" to use ado on a 64-bit windows?

Or, I have to give up ado and find some way else to read excel files in c++?

Upvotes: 1

Views: 1266

Answers (1)

athos
athos

Reputation: 6425

in case any one bumped in here, to access excel data in c++ code on a x64 windows machine with office 64-bit installed, you need

  • Download Microsoft Access Database Engine 2016 Redistributable and install
  • import msadoXX.dll in C++ code
  • using proper connection string, on the page above expanding "install instructions" there are details such as ConnectionString property to “Microsoft.ACE.OLEDB.12.0”, for Excel 97-2003 Workbook (.xls) use "Excel 8.0", for Excel Workbook (.xlsx) use "Excel 12.0 Xml" etc. Note: "Microsoft.JET.OLEDB" doesn't work.

Upvotes: 1

Related Questions