4,011
社区成员
发帖
与我相关
我的任务
分享
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","ADOEOF") rename("BOF","ADOBOF")
if (!AfxOleInit())//这就是初始化COM库
{
AfxMessageBox(_T("OLE初始化出错!"));
return FALSE;
}
_bstr_t bstrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\test2.xlsx;Extended Properties=Excel 12.0 Xml;HDR=No;IMEX=1";
try {
HRESULT hr;
hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
//m_pConnection->PutCursorLocation(adUseClient);
m_pConnection->CommandTimeout=0;
m_pConnection->Open(bstrConn, "", "", adModeUnknown);
}
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format(_T("打开Excel失败!\r\n错误信息:%s"),e.ErrorMessage());
AfxMessageBox(errormessage);
}
_bstr_t bstrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\test2.xlsx;Extended Properties='Excel 12.0 Xml;HDR=No;IMEX=1;'";