那位大侠帮忙下 谢谢了! 
能把下面的代码完善一下吗?谢谢了!在倒数第三行的保存文件,生成文件时:能不能每次导出数据都生成一个新的文件。(文件名最好是“每天日期.xls)而且新生成文件不能覆盖掉旧文件!谢谢了! 
代码如下: 
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, DBTables;type
  TForm1 = class(TForm)
    Query1: TQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
 with Query1 do
 begin
   SQL.Clear;
   SQL.Add('Select * from PersonRec where PersonName like :Name');
   Case RadioGroup1.ItemIndex of
     0:parambyname('Name').AsString:=edit1.Text;
     1:parambyname('Name').AsString:=edit1.Text + '%';
    end;
    open;
  end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
   s:TStringList;  
   str:string;  
   i:Integer;  
begin  
   str:='';  
   dbgrid1.DataSource.DataSet.DisableControls;  
   for  i:=0  to  dbgrid1.DataSource.DataSet.FieldCount-1  do  
     str:=str+dbgrid1.DataSource.DataSet.fields[i].DisplayLabel+char(9);  
     str:=str+#13;  
    dbgrid1.DataSource.DataSet.First;  
    while  not(dbgrid1.DataSource.DataSet.eof)  do  
     begin  
      for  i:=0  to  dbgrid1.DataSource.DataSet.FieldCount-1  do  
         str:=str+dbgrid1.DataSource.DataSet.Fields[i].AsString+char(9);  
         str:=str+#13;  
        dbgrid1.DataSource.DataSet.next;      
     end;    
    dbgrid1.DataSource.DataSet.EnableControls;  
   s:=TStringList.Create;  
   s.Add(str);  
   s.SaveToFile('c:\temp.xls');//保存到c:\temp.xls  
   s.Free;  
end;
end.

解决方案 »

  1.   

    procedure TForm1.OUTTOEXCEL1Click(Sender: TObject);
    var  
       s:TStringList;  
       str,fn:string;
       i:Integer;  
    begin  
       str:='';
       fn:=datetostr(now);
       dbgrid1.DataSource.DataSet.DisableControls;
       for  i:=0  to  dbgrid1.DataSource.DataSet.FieldCount-1  do  
         str:=str+dbgrid1.DataSource.DataSet.fields[i].DisplayLabel+char(9);  
         str:=str+#13;  
        dbgrid1.DataSource.DataSet.First;  
        while  not(dbgrid1.DataSource.DataSet.eof)  do  
         begin  
          for  i:=0  to  dbgrid1.DataSource.DataSet.FieldCount-1  do  
             str:=str+dbgrid1.DataSource.DataSet.Fields[i].AsString+char(9);  
             str:=str+#13;  
            dbgrid1.DataSource.DataSet.next;      
         end;    
        dbgrid1.DataSource.DataSet.EnableControls;
       s:=TStringList.Create;  
       s.Add(str);
       s.SaveToFile('c:\'+fn+'.xls');//保存到c:\当天日期.xls
       showmessage('c:\'+fn+'.xls');
       s.Free;
    end;
      

  2.   

    uses dateutils
    s.SaveToFile('c:\'+dateof(now)+'.xls');
    是这个意思吗? 
      

  3.   

    可以给点学习delphi的建议吗 
    我刚学2个星期
    买了本新概念delphi7教程  学完后感觉没有学到什么东西
    前面2个问题都做不来 
    介绍点好书和 方法 
    谢谢了