VS2013 ADO open Excel file connection is always wrong...
Time:10-02
I'm VS2013 platform using ADO to Excel file, for the first time to do it, m_pConnection connection error problem, there is no hire, to consult the great spirit is what is going on??????? The machine has been installed excel, also upgrade AccessDatabaseEngine_X64. Exe engine, I am win764bit operating system, My main operating steps are as follows: 1, in stdafx. H of lead into the ADO in
# import "C: \ Program Files \ Common Files \ System \ ado \ msado15 DLL" no_namespace rename (" EOF ", "ADOEOF") rename (" BOF, "" ADOBOF")
2, the initialization:
if (! AfxOleInit ())//this is to initialize the COM libraries { AfxMessageBox (_T (" OLE initialization error!" )); Return FALSE; }
3, m_pConnection instance attachment Excel:
_bstr_t bstrConn="Provider=Microsoft. ACE. The OLEDB. 12.0. Data Source=D: \ \ test2 XLSX; Extended Properties=12.0 Xml Excel; HDR=No. IMEX=1 "; Try { Retrieves the hr; Hr=m_pConnection. CreateInstance (" ADODB. Connection "); If (SUCCEEDED (hr)) { //m_pConnection - & gt; PutCursorLocation (adUseClient); M_pConnection - & gt; CommandTimeout=0; M_pConnection - & gt; Open (bstrConn, ""," ", adModeUnknown); } } Catch _com_error (e) {
Cstrings errormessage; Errormessage. The Format (_T (" open the Excel failed! \ r \ n error message: % s "), e.E rrorMessage ()); AfxMessageBox (errormessage); }
Run this code suggests the following error:
When changing the connection string to:
_bstr_t bstrConn="Provider=Microsoft. ACE. The OLEDB. 12.0. Data Source=D: \ \ test2 XLSX; Extended Properties='Excel Xml 12.0; HDR=No. IMEX=1; '";
Note: changes are in the Extended Propertiec=behind with single quotes, and added a semicolon after the IMEX=1, because I checked some tutorial is so of the writing, also has the kind of writing the above, but still there is an error, you will be prompted:
If you remove the semicolon after IMEX=1, will appear in front of the errors, if the Extended Properties after=add double quotation marks, also appeared in front of that kind of mistake, anyway I tried multiple online tutorial will appear this two kinds of errors, I really didn't recruit, asked the great spirit, this problem is out in where? Thank you,,, Data Source=D: \ \ this path double slash, single slash, against all tried, also not line,,,