读取EXCEL中的记录!!!(100分)

C

cp0574

Unregistered / Unconfirmed
GUEST, unregistred user!
我想读取EXCEL中某些字段的记录,从首到尾,然后将这些记录保存成文本文件
我使用了Adoconnection1,Adotable1,Datasource1,Dbgrid1.
Adoconnection1的连接字符串Connect_Str为:
Connect_Str:='Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite;ExtendedProperties=Excel 8.0';
Connect_Str:=Connect_Str+';Data Source='+AXLSFileName;
Connect_Str:=Connect_Str+';Persist Security Info=False';
在测试连接时,发生错误:"测试连接失败,因为初始化提供程序时发生错误,找不到可安装的ISAM."
望大家告我这是什么错误?怎么解决?注:这个连接字符串我是在全文检索后找到的.
于是我修改连接字符串Connect_Str为
Connect_Str:='Provider=MSDASQL.1;Persist Security Info=False;'+
'Extended Properties="DSN=Excel Files;DBQ='+AXLSFileName+
';MaxBufferSize=2048;PageTimeout=5;"';
这次连接测试通过!,但Dbgrid1中却只显示了XLS文件中的第一列数据,在我的XLS文件中我一共有5列数据.
这又是什么原因?怎么解决?

其他信息:winxp+delphi6+excel2000
adotable1的tabledirect设置为true,tablename为dsf(dsf是什么东西???它是怎么得到的???)
 
试试如下的方法:
加入ADOTABLE ,DATASOURCE,DBGRID;
加入一个BUTTON,在其ONCLICK事件中加入:
adotable1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/MY_DELPHI/Book1.xls;Extended Properties=excel 8.0;Persist Security Info=False';
adotable1.TableName:='[XXX$]'; //XXX为你的EXCEL中SHEET的名子,注,结尾要加'$'
adotable1.Active:=true;

datasource1.DataSet:=adotable1;
dbgrid1.datasource:=datasource1;


 
用ADOCONNECT来操作xls文件啊,ConnectionString的属性设为
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Extended Properties='Excel 8.0;HDR=Yes'
注意:TADODataSet中的CommandText属性要设为
select * from [Sheet1$]
 
在table的TABLENAME属性里,下拉框里怎么看不到表格名?
必须手工加才可以吗?
 
不知道哪里改了下,行了
 
顶部