当前位置:首页 » 编程软件 » 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)

热点内容
iis安装sql 发布:2025-03-20 06:05:31 浏览:148
制作自解压安装 发布:2025-03-20 05:41:49 浏览:304
华为连接电视密码是多少 发布:2025-03-20 05:31:11 浏览:493
算法第五版 发布:2025-03-20 05:17:57 浏览:730
湖南台访问 发布:2025-03-20 05:10:32 浏览:38
脚本和秒抢 发布:2025-03-20 05:06:29 浏览:592
b35锁如何设置密码 发布:2025-03-20 05:06:27 浏览:905
淘宝如何租云服务器 发布:2025-03-20 05:05:12 浏览:213
编程忌讳 发布:2025-03-20 04:58:35 浏览:427
国家知识产权专利数据库 发布:2025-03-20 04:54:29 浏览:416