本文整理自网络,侵删。
引用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+';Extended Properties=excel 12.0;'+ 'Persist Security Info=True';//注意不能为false Conn.LoginPrompt:=false; Conn.Connected:=true; qry.Connection:=Conn; qry.close; qry.SQL.Clear; qry.SQL.add('select * from ['+sheet1+'$]'); qry.Active:=true;end;
附上各个EXCEL版本的版本号:版本号 Excel名称2.0 Excel 2.03.0 Excel 3.04.0 Excel 4.05.0 Excel 5.07.0 Excel 958.0 Excel 979.0 Excel 200010.0 Excel XP11.0 Excel 200312.0 Excel 200713.0 Excel 201015.0 Excel 2013――――――――――――――――
原文链接:https://blog.csdn.net/songling418/article/details/14054359
相关阅读 >>
Delphi xe增强的rtti妙用--动态创建包中的窗口类
Delphi mediaplayer循环播放mp3所有音乐文件问题?
Delphi xe system.netencoding 字符串base64编码解码
更多相关阅读请进入《Delphi》频道 >>