Ver Mensaje Individual
  #2  
Antiguo 22-09-2007
pcicom pcicom is offline
Miembro
 
Registrado: may 2003
Ubicación: MONTERREY MEXICO
Posts: 253
Reputación: 24
pcicom Va por buen camino
Cita:
Empezado por GustavoCruz Ver Mensaje
Prueba con esta funcion que escribio uno de los muchos gurus de delphi


Código Delphi [-]
 
procedure SendToExcel(aDataSet: TDataSet); 
var 
  PreviewToExcel: TExcelApplication; 
  RangeE: Excel2000.ExcelRange; //or RangeE: Excel97.Range 
  I, Row: Integer; 
  Bookmark: TBookmarkStr; 
begin 
  PreviewToExcel := TExcelApplication.Create(Self); 
  PreviewToExcel.Connect; 
  PreviewToExcel.Workbooks.Add(NULL, 0); 
  RangeE := PreviewToExcel.ActiveCell; 
  for I := 0 to aDataSet.Fields.Count - 1 do 
  begin 
    RangeE.Value := aDataSet.Fields[i].DisplayLabel; 
    RangeE := RangeE.Next; 
    Application.processmessages;

  end; 
  aDataSet.DisableControls; 
  try 
    Bookmark := aDataSet.Bookmark; 
    try 
      aDataSet.First; 
      Row := 2; 
      while not aDataSet.EOF do 
      begin 
    Application.processmessages;

        //Write down Record As Row in msExcel 
        RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; 
        for I := 0 to aDataSet.Fields.Count - 1 do 
        begin 
          RangeE.Value := aDataSet.Fields[i].AsString; 
          RangeE := RangeE.Next; 
    Application.processmessages;

        end; 
        aDataSet.Next; 

        Inc(Row); 
      end; 
    finally 
    Application.processmessages;

      aDataSet.Bookmark := Bookmark; 

    end; 
  finally 
    aDataSet.EnableControls; 
  end; 
    Application.processmessages;

  RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + 
IntToStr(Row - 1)]; 
    Application.processmessages;

  RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); 
    Application.processmessages;

  PreviewToExcel.Visible[0] := True; 
  PreviewToExcel.Disconnect; 
end;

La cuestión es que al implementarlo demora mucho para mostrar el resultado, esto cuando el dataset es grande

Puedes Agregar entre el CODIGO instrucciones:

Application.processmessages;

Y Veras que se acelerara la presntacion..
__________________
Poco ha de saber el que no pregunta.. Yo por eso soy un pregunton
Responder Con Cita