用aSheet.Paste命令;由于数据量巨大,所以粘贴会花点时间,享用进度条显示其进程。
    
procedure Tbrowse.ExportToExcel(defaultName: string;
  Grid: TDBGridEh);
var
  lcid:integer;
var
    ls_FileName:string;
    I,K,M,N:integer;
      y       :integer;
    tsList  :TStringList;
    s       :string;
    aSheet:Variant;
    form_clip:Tform_clip;
begin
  if not Grid.DataSource.DataSet.Active then // if 5
  begin
    Application.Messagebox('未与数据库连接!','消息',mb_OK+mb_IconStop);
    Exit;
  end; //end if 5
  Grid.DataSource.DataSet.DisableControls;
  //如果未装Excel,则退出。
  try   //try 30
    Excel.Connect;                  // 打开Excel
    Excel.Visible[0]:=false;         // 显示Excel
    Excel.Workbooks.Add(xlWBATWorksheet,0);
    aSheet:=excel.Worksheets.Item[1];
  except
    Application.MessageBox('无法打开Xls文件,请确认已经安装EXCEL.','警告',mb_OK+mb_IconStop);
    Exit;
  end;   //end try 30
  Dlg_SaveToFile.FileName:=defaultName;
  if not Dlg_SaveToFile.Execute Then Exit;
  ls_FileName:=Dlg_SaveToFile.FileName;
  try  //try 15
    K:=1;
    lcid := LOCALE_USER_DEFAULT;
    N:=Grid.Columns.count;
    I:=Grid.DataSource.DataSet.RecordCount;
    tsList:=TStringList.Create;
    FormProgress:=TFormProgress.Create (self);
    FormProgress.Show;
try
    try
    Grid.DataSource.DataSet.first;
    while not Grid.DataSource.DataSet.Eof do
     begin
                    s:='';
                    for y:=0 to n-1 do
                    begin
                        s:=s+Grid.DataSource.DataSet.Fields[y].AsString+#9;
                        Application.ProcessMessages;
                    end;
                    tsList.Add(s);
                    FormProgress.ProgressBar1.Position:=Trunc((K*100)/I);
                    FormProgress.Refresh;
                    INC(K);
                    Grid.DataSource.DataSet.next;
     end;
     finally
     FormProgress.Hide;
     FormProgress.free;
     end;
    Clipboard.AsText:=tsList.Text;
    aSheet.Paste;
    Excel.DisplayAlerts[lcid]:= false;
    aSheet.Saveas(ls_FileName);
    MessageBox(Application.Handle,'数据导出完毕!','系统提示',MB_ICONINFORMATION or MB_OK);
     finally
        tsList.Free;
        Grid.DataSource.DataSet.EnableControls;
        Excel.disconnect;
        aSheet:=Unassigned; //释放VARIANT变量
    end;
    except
      Application.Messagebox('数据导出错误!','消息',mb_OK+MB_ICONINFORMATION);
      Exit;
    end;   //end try 80

解决方案 »

  1.   

    你的代码有什么问题呢?
    我觉得一次paste过去不如一条条记录直接传过去,你可以做个试验对比一下。
      

  2.   

    通过Paste是快一些的,那是你的内存足够的情况下,如果不足的化会很惨的!
      

  3.   

    建议楼主浆每次Copy的东西减少一些分多次进行,这样既可以控制进度,也可以加快速度的!
      

  4.   

    开始导入的地方加入
      form*.show;                                //进度显示
      application.ProcessMessages;                      //显示进度窗字体
    结束的地方加入
     application.ProcessMessages;
     form3.close;form*中放个 Animate控件
    unit*中Animate1.Active:=true;
    这样就可以了
      

  5.   

    开始导入的地方
      form3.show;                                          //进度显示
      application.ProcessMessages;                     //显示进度窗字体
    结束的地方
     application.ProcessMessages;
     form3.close;form中加个Animatel 控件
    unit中Animate1.Active:=true;
      

  6.   

    同意shengs(上网要小心,慎防意外生!) 
    减少Application.ProcessMessages操作,可以在
    if i mod 50 = 0 then Application.ProcessMessages;