ole 连接 excel 查数据 ,各版本的连接字符串


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;'+

————————————————
版权声明:本文为CSDN博主「一意弧行」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/songling418/article/details/14054359
发布了90 篇原创文章 · 获赞 33 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/y281252548/article/details/102601243
今日推荐