2,497
社区成员
发帖
与我相关
我的任务
分享
var
path,s:string;
con:Boolean;
i,j:Integer;
begin
path:=ExtractFilePath(Application.ExeName);
self.ADOConnection3.Connected:=False;
self.ADOConnection3.ConnectionString:='Provider=MSDASQL.1;Persist Security Info=False;'+
'Data Source=study;Extended Properties="DSN=study;DBQ='+
path+'study;DefaultDir='+path+';DriverId=790;FIL=excel 8.0;'+
'MaxBufferSize=2048;PageTimeout=5;";Initial Catalog='+path+'study';
try
self.ADOConnection3.Connected:=True;
con:=True;
except
con:=False;
end;
if con=False then
Exit;
self.ADOQuery4.Close;
self.ADOQuery4.Connection:=self.ADOConnection3;
Self.ADOQuery4.SQL.Clear;
self.ADOQuery4.SQL.Add('select * from [sheet1$]');//读取sheet1工作表
self.ADOQuery4.Open;
i:=self.ADOQuery4.Fields.Count;
for j:=0 to i-1 do
begin
s:=self.ADOQuery4.Fields[j].FieldName;//字段名
self.ListBox1.Items.Add(s);
end;