Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Servers
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 25-01-2006
Anabel Anabel is offline
Miembro
 
Registrado: may 2003
Ubicación: D.F. México
Posts: 63
Poder: 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
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Crear Excel con 2 hojas de trabajo miquellg Servers 1 25-05-2006 09:52:50
Obtener informacion de hojas de datos de excel jander.atlas C++ Builder 1 16-01-2006 22:50:16
Como crear un libro de excel con 6 hojas no estoy usando el ExcelApplication Martha Ayala Servers 3 24-10-2005 18:33:49
Obtener nombres de las hojas al abrir un archivo (fichero) de Excel atirado API de Windows 1 17-05-2004 21:50:31
Excel con varias hojas Ricardo Alfredo Varios 0 22-01-2004 15:07:33


La franja horaria es GMT +2. Ahora son las 23:03:48.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi