2,495
社区成员
发帖
与我相关
我的任务
分享
var
a_cc: TStrings;
begin
a_cc :=TStringList.Create;
with ADOConn do begin
ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + OpenDialog1.FileName + ';Extended Properties=excel 8.0;Persist Security Info=false';
Connected := True;
GetTableNames(a_cc);{将EXCL文件中的表格名赋值于a_cc}
end;
with adoquery1 do begin
Close;
SQL.text:='select * from ['+a_cc[0]+']'{a_cc[0]得到EXCEL文件中的第一个表格的名}
Open;
end;
end;
if opendialog1.execute then
with adoquery do
begin
close;
sql.clear;
sql.add('select * from opendatasource(''microsoft.jet.oledb.4.0'',''data source="'+opendialog1.filename+'"',user id=admin;password=;extended properties=excel 5.0')...[sheet1$]');
open;
end;