ADO读Excel的问题
//打开Excel
CoInitialize(NULL);
ConnectionString = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
ConnectionString += strExcelName; //excel file name
ConnectionString += _T(";Extended Properties="Excel 8.0;HDR=Yes;IMEX=0"");
BSTR resultsString = ConnectionString.AllocSysString();
pCon_ex.CreateInstance(__uuidof(Connection));
//resultsString = ConnectionString.AllocSysString();
HRESULT _hr = pCon_ex->Open(resultsString,"","",adModeUnknown);
if(FAILED(_hr))
{
AfxMessageBox(_T("打开excel失败"));
return FAIL;
}
//读数据
strSQL.Format(_T("select * from [sheet1$] where 出勤 is not null"));
pRst=pCon_ex->Execute((_bstr_t)strSQL,NULL,adCmdText);
sql.Format(_T("select count(*) as geshu from [sheet1$] where 出勤 is not null "));
Rs1=pCon_ex->Execute((_bstr_t)sql,NULL,adCmdText);
_variant_t vCount=Rs1->GetCollect("geshu");
LONG nNum=vCount.lVal; //符合条件的记录个数
if (nNum < 1)
{//未搜索到有效数据
return FAIL;
}