2,507
社区成员




dm.ADOConnUser.ConnectionString:=
'Driver={Microsoft Excel Driver (*.xls)};DBQ= ' +Trim(EdtXlsFile.Text);
if UpperCase(ExtractFileExt(Trim(EdtXlsFile.Text)))='XLSX' then
begin
//为excel 2007 文件
dm.ADOConnUser.ConnectionString:=
'Provider=Microsoft.ACE.OLEDB.12.0;
Password='''';Data Source='+
Trim(NewAccountMonthWizard.EdtXlsFile.Text)
+';Extended Properties=''Excel 12.0;IMEX=1;HDR=YES'';
Persist Security Info=True;';
end
else
begin
dm.ADOConnUser.ConnectionString:='Provider=
Microsoft.Jet.OLEDB.4.0;Data Source='+
Trim(EdtXlsFile.Text) +';
Extended Properties=Excel 8.0
;Persist Security Info=False';
end ;
原来是参数问题
dm.ADOConnUser.GetTableNames(lsttablename.Items ,False ); 就不行
dm.ADOConnUser.GetTableNames(lsttablename.Items ,True );就可以了
procedure TADOConnection.GetTableNames(List: TStrings;
SystemTables: Boolean);
var
TypeField,
NameField: TField;
TableType: string;
DataSet: TADODataSet;
begin
CheckActive;
DataSet := TADODataSet.Create(nil);
try
OpenSchema(siTables, EmptyParam, EmptyParam, DataSet);
TypeField := DataSet.FieldByName('TABLE_TYPE'); { do not localize }
NameField := DataSet.FieldByName('TABLE_NAME'); { do not localize }
List.BeginUpdate;
try
List.Clear;
while not DataSet.EOF do
begin
TableType := TypeField.AsString;
if (TableType = 'TABLE') or (TableType = 'VIEW') or { do not localize }
(SystemTables and (TableType = 'SYSTEM TABLE')) then { do not localize }
List.Add(NameField.AsString);
DataSet.Next;
end;
finally
List.EndUpdate;
end;
finally
DataSet.Free;
end;
end;