当前位置:首页 » 编程软件 » excelvc编程

excelvc编程

发布时间: 2023-08-11 18:57:38

Ⅰ VC++(MFC)如何从对话框写数据到Excel

MFC访问EXCEL,那可是比较麻烦的了。给个以前做过的项目。是访问数据库的 你自己整理着看下 希望有帮助。
if(m_bDataBase) //有数据库
{
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
m_pConnection->ConnectionTimeout=3;///设置超时时间为3秒
CString szOpen = theApp.m_szDataMisDir;
if(szOpen.Right(1) != "\\")
szOpen += "\\";
//hr = m_pConnection->Open(Filepath,"","",adModeUnknown);
#ifndef _OFFICE97
szOpen = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+szOpen+"BiocaDatabase.mdb;";
#else
szOpen = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source="+szOpen+"BiocaDatabase.mdb;";
#endif

hr = m_pConnection->Open((_bstr_t)szOpen,"","",adModeUnknown);
}
}
catch(_com_error e)//捕捉异常
{
CString temp;
if(m_bChinese) temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
else temp.Format("Connecting database failure:%s",e.ErrorMessage());
AfxMessageBox(temp);
m_pConnection = NULL;
}

//如果当前数据库为空,则导入最近使用的数据库
if(m_pConnection!=NULL)
{
CString szSQL = "SELECT * FROM TestData";
_RecordsetPtr pSearchRecordSet;
try
{
pSearchRecordSet.CreateInstance("ADODB.Recordset");
pSearchRecordSet->Open((_variant_t)szSQL,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(pSearchRecordSet->adoEOF)
{

if(!CopyFile(m_szDesFileName1,m_szDataMisDir+"\\BiocaDatabase.mdb",FALSE))
{
//判断是否是装完软件后第一次运行
int RunNo=GetProfileInt("RunNo","No",0); //第一次运行
if(RunNo==0) WriteProfileInt("RunNo","No",1); //已经运行过了
else
{
if(m_bChinese) AfxMessageBox("导入数据库失败!");
else AfxMessageBox("Input database failure!");
}
}

}
}
catch(_com_error e)///捕捉异常
{
CString temp;
if(m_bChinese) temp.Format("导入数据库出错:%s",e.ErrorMessage());
else temp.Format("Input database failure:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
} //if(!m_pConnection=NULL)

} //if(m_bDataBase)

热点内容
安卓手机电影怎么投屏到ipad上 发布:2025-03-20 04:27:23 浏览:677
苹果安卓基于什么开发 发布:2025-03-20 04:20:52 浏览:520
算法化是 发布:2025-03-20 03:48:20 浏览:771
拆二代访问 发布:2025-03-20 03:47:34 浏览:63
随机数排序c语言 发布:2025-03-20 03:35:31 浏览:498
当前页面脚本发生错误类型不匹配 发布:2025-03-20 03:26:47 浏览:992
strutsajax上传图片 发布:2025-03-20 03:25:03 浏览:386
手机在线缓存 发布:2025-03-20 03:21:06 浏览:46
ftp路径上传时间 发布:2025-03-20 03:13:42 浏览:104
电脑连接通讯服务器失败怎么回事 发布:2025-03-20 03:10:30 浏览:287