本文介绍了这段代码(ado访问excel文件和写入数据)可以在win7(32bit)系统上运行,并且可以在win7(64bit)上编译和链接,但是无法写入数据,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 //#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF", "adoEOF") write at stdafx.h CoInitialize(NULL);_ConnectionPtr pCon_ex; void write_excel(CString dest_file) { ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; ConnectionString += excel_path; //excel file name ConnectionString += ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=0\""; BSTR resultsString = ConnectionString.AllocSysString(); pCon_ex.CreateInstance(__uuidof(Connection)); pCon_ex->Open(resultsString,"","",adModeUnknown); _RecordsetPtr m_ownpRecordset; m_ownpRecordset.CreateInstance(__uuidof(Recordset)); try { m_ownpRecordset->Open("SELECT * FROM [清单$]",// 查询道路表中所有字段 pCon_ex.GetInterfacePtr(), // 获取库接库的IDispatch指针 adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } try { m_ownpRecordset->MoveFirst(); int max_count=20;for(int i=0;i< max_count;i++){ m_ownpRecordset->AddNew(); CString astr=BDialog->m_StandrdList.GetItemText(i,0); CString bstr=BDialog->m_StandrdList.GetItemText(i,1);CString estr=BDialog->m_StandrdList.GetItemText(i,3);CString fstr=BDialog->m_StandrdList.GetItemText(i,4); _variant_t t = _variant_t(long(0)); m_ownpRecordset->PutCollect(&t,_variant_t(astr)); t = _variant_t(long(1)); m_ownpRecordset->PutCollect(&t,_variant_t(bstr)); t = _variant_t(long(4)); m_ownpRecordset->PutCollect(&t,_variant_t(estr)); t = _variant_t(long(5)); m_ownpRecordset->PutCollect(&t,_variant_t(fstr)); } m_ownpRecordset->Update(); m_ownpRecordset->Close(); m_ownpRecordset = NULL; pCon_ex.Release(); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); }CoUninitialize(); } 推荐答案 这篇关于这段代码(ado访问excel文件和写入数据)可以在win7(32bit)系统上运行,并且可以在win7(64bit)上编译和链接,但是无法写入数据,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 17:47