社区
数据库
帖子详情
请问用ADO能不能查询Excel表格
zz421
2003-08-21 04:10:57
我要开发一个绘图程序,其中的点的数据用Excel表格存储比较方便,单不只能不能查询,怎样得到其中的值,用与绘图,请各位大师给予指点
...全文
71
2
打赏
收藏
请问用ADO能不能查询Excel表格
我要开发一个绘图程序,其中的点的数据用Excel表格存储比较方便,单不只能不能查询,怎样得到其中的值,用与绘图,请各位大师给予指点
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
康斯坦汀
2003-08-22
打赏
举报
回复
为什么要用excel, ADO可以访问excel, 但是要带上很多dll,
看你的需求,完全用不着excel,
找本MFC的书,看看“类的序列化”的相关内容,使用序列化功能,存在文件里,
读写都很容易。完全满足你的要求。
例子:MFC中自带的绘图程序例子中都有这样的内容。比如经典的"SCRIBBLE"
ZHENG017
2003-08-22
打赏
举报
回复
#include <stdio.h>
#include <windows.h>
#include <comdef.h>
#import "c:\program files\common files\system\ado\msado20.tlb" no_namespace rename ("EOF", "adoEOF")
HRESULT hr;
int main()
{
hr=CoInitialize(NULL);
_ConnectionPtr m_pConnection;
_CommandPtr m_commandptr;
_RecordsetPtr m_pUserSet;
try
{
//使用odbc的连接字符串
// _bstr_t conn("DRIVER={Microsoft Excel Driver (*.xls)};DriverId=790;DBQ=E:\\temp.xls;DefaultDir=e:\\;");
//使用ole db的连接字符串
_bstr_t conn("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\temp.xls;Extended Properties=""Excel 8.0;""" );
m_pConnection.CreateInstance (__uuidof(Connection));
m_pConnection->Open (conn,"","",-1);
_RecordsetPtr pRstSchema = NULL;
pRstSchema = m_pConnection->OpenSchema(adSchemaTables);
while(!(pRstSchema->adoEOF))
{
_bstr_t table_name = pRstSchema->Fields->GetItem("TABLE_NAME")->Value;
printf("Table Name: %s\n",(LPCSTR) table_name);
_bstr_t table_type = pRstSchema->Fields->GetItem("TABLE_TYPE")->Value;
printf("Table type: %s\n\n",(LPCSTR) table_type);
pRstSchema->MoveNext();
}
//比方说如果table_name为test$的话,那么sqltext中的表名应该为[test$],就是在表名前加上"[]"
//就是这个"[]"浪费了我很多时间
_bstr_t sqltext="SELECT * from [test$] ";
m_commandptr.CreateInstance (__uuidof(Command));
m_pUserSet.CreateInstance (__uuidof(Recordset));
m_commandptr->ActiveConnection =m_pConnection ;
m_commandptr->CommandText =sqltext;
m_commandptr->CommandType =adCmdText;
m_pUserSet=m_commandptr->Execute (NULL,NULL,adCmdUnknown);
_variant_t filed[12];
_bstr_t filedname[12];
bool befirstrow=true;
while (!m_pUserSet->adoEOF )
{
long kk=m_pUserSet->GetFields ()->GetCount ();
for (long uu=0;uu<kk;uu++)
{
filedname[uu]=m_pUserSet->GetFields ()->GetItem ((_variant_t)uu)->GetName ();
filed[uu]=m_pUserSet->GetCollect (filedname[uu]);
printf("%s\t ",(LPCSTR)(_bstr_t)(filed[uu]));
}
printf("\r\n");
m_pUserSet->MoveNext ();
}
}
catch(_com_error * e)
{
MessageBox(NULL,"",e->ErrorMessage(),MB_OK);
}
catch(...)
{
long errorcount=m_pConnection->GetErrors ()->GetCount ();
char add[255];
strcpy(add,"");
for (short i=0;i<errorcount;i++)
{
strcat(add,m_pConnection->GetErrors ()->GetItem (_variant_t((short)i))->GetDescription ());
}
printf(add);
}
CoUninitialize();
return 0;
}
VBA+
ADO
连接
Excel
表格
查询
操作数据(SQL语句操作)
VBA+
ADO
连接
Excel
表格
查询
操作数据(SQL语句操作) SQL语句操作
表格
Delphi用
ADO
把
Excel
内容读取至
表格
delphi2007,无第三方控件,使用用
ADO
控件把
Excel
内容读取至DbGrid
表格
中。简单好用,一看就会。
VBA从入门到精通(控件+类模块+
ADO
+SQL数据库)
本课程属性
Excel
VBA中比较高阶的课程,主要讲解关于各种事件的应用,各种控件的应用,如果使用类模块,如果在VBA用调用SQL语句去处理数据库中的数据等操作。学习完成本课后,你可以在
Excel
中开发各种小型应用系统。以下是课程主要内容。第1章:工作表,工作簿常用事件。第2章:窗体控件应用第3章:ActiveX控件应用第4章:类模块应用第5章:vba+
ado
+sql第6章:实战应用(考试系统开发)
DELPHI
ADO
导出
EXCEL
DELPHI7
ADO
导出
EXCEL
表格
,仅供学习之用
VC中用
ADO
访问
EXCEL
电子
表格
对office各个工具的访问基本一样,
EXCEL
就和ACCESS的访问基本一样,只是这个参数_bstr_t strConnect ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.xls;Extended Properties=
Excel
8.0;";略有区别。 传的附件好像不正确,后面传上正确的。
数据库
4,012
社区成员
39,817
社区内容
发帖
与我相关
我的任务
数据库
VC/MFC 数据库
复制链接
扫一扫
分享
社区描述
VC/MFC 数据库
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章