Ver Mensaje Individual
  #5  
Antiguo 23-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
  xFile:TextFile;
  cFile:String; 
  I, Row: Integer; 
begin 
  cFile := 'reporte.xls';
  AssignFile(xFile,cFile);
  writeln(xFile,'');
  writeln(xFile,'');

  for I := 0 to aDataSet.Fields.Count - 1 dobegin 
         
    RangeE.Value := aDataSet.Fields[i].DisplayLabel; 
    RangeE := RangeE.Next; 
  end;
  writeln(xFile,'');
 
  aDataSet.DisableControls; 
  try 
    Bookmark := aDataSet.Bookmark; 
    try 
      aDataSet.First; 
      Row := 2; 
      whilenot aDataSet.EOF dobegin//Write down Record As Row in msExcel 
        RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; 
        for I := 0 to aDataSet.Fields.Count - 1 dobegin 
          RangeE.Value := aDataSet.Fields[i].AsString; 
          RangeE := RangeE.Next; 
        end; 
        aDataSet.Next; 
        Inc(Row); 
      end; 
    finally 
      aDataSet.Bookmark := Bookmark; 
    end; 
  finally 
    aDataSet.EnableControls; 
  end; 
  RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + 
IntToStr(Row - 1)]; 
  RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); 
  PreviewToExcel.Visible[0] := True; 
  PreviewToExcel.Disconnect; 

  writeln(xFile,'
'
); close(xFile); end;

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


OTRA FORMA es que CREES el XLS al vuelo como un archivo tipo HTML con extencin de EXCEL .xls, y despues lo abres..
__________________
Poco ha de saber el que no pregunta.. Yo por eso soy un pregunton
Responder Con Cita