引用ComObj这个单元
Type
Conn: TADOConnection;
qry: TADOQuery;
.
.
.
var
Excel: OLEVariant;
ExcelVersion: string;
begin
try
Excel := CreateOLEObject('EXCEL.Application');
ExcelVersion := Excel.version;
finally
Excel.Quit;
Excel := UnAssigned;
end;
Conn.Close;
if ExcelVersion = '11.0' then
//Excel2003及早期的版本
Conn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
filename+';Extended Properties=excel 8.0;'+
'Persist Security Info=false;'
else //Excel2007及以后的版本
Conn.ConnectionString:='Provider=Microsoft.ACE.OLEDB.12.0;Data Source='+
filename+';E