Ver Mensaje Individual
  #2  
Antiguo 25-01-2006
Anabel Anabel is offline
Miembro
 
Registrado: may 2003
Ubicación: D.F. México
Posts: 63
Reputación: 22
Anabel Va por buen camino
Thumbs up

Hola Osvaldo!!!

Espero te sirva lo siguiente:

Necesitas de Delphi:
-TForm (obvio!!)
-TQuery
-SaveDialog
-TExcelapplication

Código Delphi [-]
var
  LCID, LineNumber, h, s: Integer;
  LineString :String; //
  WorkBk : _WorkBook; //  Define a WorkBook
  WorkSheet : _WorkSheet; //  Define a WorkSheet
  IIndex : OleVariant;
begin
  With SaveDialog1 do
  begin
    FileName:= '';
    Filter:='Excel files|*.XLS;All Files|*.*';
    DefaultExt := 'XLS';
    Title:= 'Exportando a Excel';
    IIndex := 1;
    if execute then
    begin
      //Empieza el codigo para crear reporte en Excel
      LCID := GetUserDefaultLCID;
      With ExcelApplication1 do
      begin
        connect;
        try
          visible[LCID]:= True;
          Workbooks.Add(EmptyParam,LCID); //Creamos el libro
          WorkBk := WorkBooks.Item[IIndex];//Asignamos un Indice al libro
          StandardFontSize[LCID] := 8;
          StandardFont[LCID] := 'Arial';
          h := 0;  s := 0;
         With qry do
         begin
             //aqui abres tu query
                 While not Eof do
                 begin
                      s := s + 1;
                     if h < 3 then   // puedes también usar un FOR, yo aproveche el While de qry, ya que queria que cad registro cayera en una hoja diferente de Excel
                     begin
                        h := h+1;
                        WorkSheet := WorkBk.WorkSheets.Get_Item(h) as _WorkSheet;//Seleccionamos una hoja del libro seleccionado
                     end
                     else
                     begin
                        WorkBk.Worksheets.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam,LCID);                
                        WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;//Seleccionamos una hoja del libro seleccionado
                       end;
          Next;
         end   
         end;
          ActiveWorkbook.SaveAs(FileName,xlNormal,'','',false,false,xlNochange,xlUserResolution,False,EmptyPar  am,EmptyParam,LCID);
          //Quit;
        finally
          disconnect;
        end; //try
      end;//ExcelApplication1
    end; //execute
  end;//SaveDialog1

Bye!!!
__________________
Ana
Responder Con Cita