50分在线请教一导出excel文件的问题
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误
CString strdate;
strdate="2005-03-25";
CString sql;
sql.Format("SELECT * FROM recordtable where record_date>='%s' and slave_number='%s'",strdate,"04");
try
{
m_pRecordset->Open(bstr_t(sql), // 查询recordtable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//-------要求
1、建立一excel文件后,在excel表一的开头写一些必要信息
2、后写字段名
3.接着m_pRecordset里的数据写到一excel文件里面