Delphi ADO 连接 Excel (附Excel各个版本的版本号)


本文整理自网络,侵删。

 
引用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.0
3.0       Excel 3.0
4.0       Excel 4.0
5.0       Excel 5.0
7.0       Excel 95
8.0       Excel 97
9.0       Excel 2000
10.0     Excel XP
11.0     Excel 2003
12.0     Excel 2007
13.0     Excel 2010
15.0     Excel 2013
――――――――――――――――

原文链接:https://blog.csdn.net/songling418/article/details/14054359

相关阅读 >>

Delphi连接access提示密码无效解决一例

Delphi xe增强的rtti妙用--动态创建包中的窗口类

Delphi 获取当前进程的父进程

Delphi xe6通过wifiapi得到wifi信息

Delphi mediaplayer循环播放mp3所有音乐文件问题?

Delphi汉字与多字节编码的转换

Delphi webbroker 制作网站

Delphi httpget 判断链接是否可以访问

Delphi 复制动态数组

Delphi xe system.netencoding 字符串base64编码解码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...