如何在没有excel的情况下将数据导出成excel文件
研究了半天,终于找出了如何在没有excel的情况下将数据导出成excel文件的方法。
方法一:
在窗体上放置一个TADOQuery组件,通过OleDB连接到一个数据表,设定其SQL属性
为:
select * into mysheet in "c:\temp.xls" "Excel 8.0;" from Vendors 
此句SQL命令的意思是从表Vendors 中检索所有数据,把检索出来的数据保存到
c:\temp.xls 文件的mysheet表单中。"Excel 8.0;"指定了OLEDB使用的ISAM驱动
,分号不能省略。
设定active=true即可。
这种方式只要客户端电脑上有OLDB驱动即可,不过这种方式只能连接被OLEDB支持的数据库,比如Access等。
方法二:
var  I: Integer;  
Str: String;  StrList: TStringList;
begin  StrList := TStringList.Create;  
try    
  with ADOTable1 do    
  begin      
    First;     
    while not Eof do     
    begin        
      Str := '';        
      for I := 0 to FieldCount-1 do          
      Str := Str + Fields[I].AsString + #9;  
      StrList.Add(Str);        
      Next;      
   end;      
   StrList.SaveToFile('test.xls');    
  end;    
    StrList.Free;  
  except    
    StrList.Free;  
  end;
end;
这种方式对客户端没有任何要求使用起来最方便。
欢迎访问我的主页:http://lincosoft.go.nease.net