Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 20-01-2015
Avatar de jeremiselxi
jeremiselxi jeremiselxi is offline
Miembro
 
Registrado: ago 2008
Posts: 199
Poder: 16
jeremiselxi Va por buen camino
Exportar bd e imagen a excel desde Delphi7

Buenas tardes Colegas.

Estoy presentando la siguiente situación. Necesito exportar a Excel una BD y esto lo hago con el siguiente código:

Código Delphi [-]

procedure TForm1.ExportaraexcelClick(Sender: TObject);
var
  Libro : _WORKBOOK;
  Hoja  : _WORKSHEET;
  i,colora:Integer;
  FileImage : String;
begin

  FileImage := ExtractFilePath(Application.ExeName)+'\Chart.bmp';

i:=0;
colora:=1;



Libro := Excel.Workbooks.Add(Null, 0);
Hoja  := Libro.Sheets[1] as _WORKSHEET;


//titulo
i:=i+1;


        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;


Hoja.Cells.Item[i,1]:='Totales';
Hoja.Cells.Item[i,2]:='Actividades Realizadas';



//Insertamos todos los registros al excel  y en dbgrid 1
  with table do
    begin
    first;
      while not EOF Do
        begin
        i:=i+1;
        Hoja.Cells.Item[i,1]:=DBGrid1.Fields[0].AsString;
        Hoja.Cells.Item[i,2]:=DBGrid1.Fields[1].AsString;

        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;

//        Hoja.Cells.Item[i,3]:=DBGrid1.Fields[2].AsString;
        Next;
   end;//while
end;//with





//Luego insertamos el total

        i:=i+1;
        Hoja.Cells.Item[i,1]:= 'Total ';
//      Hoja.Cells.Item[i,2]:= total.Caption;


Excel.Visible[0] := true;

ShowMessage('Exportado con Exito!');

end;

Ahora bien, para exportar una imagen a Excel lo hago de la siguiente manera:

Código Delphi [-]
uses ComObj;

procedure TForm1.exportargraficoaexcelClick(Sender: TObject);
var excel1: OleVariant;
begin
 excel1 := CreateOleObject('Excel.Application');
 excel1.Workbooks.add.worksheets[1].shapes.addpicture(ExtractFilePath(Application.ExeName)+'\Chart.bmp', False, True, 6, 6, 666, 666);
 excel1.visible := True
end;

pero por mas que he tratado me salen en libros diferentes y necesito que salga en uno solo.

Lo intenté de esta manera y aún así me salen en libros diferentes.

Código Delphi [-]
procedure TForm1.ExportaraexcelClick(Sender: TObject);
var
  Libro : _WORKBOOK;
  Hoja  : _WORKSHEET;
  i,colora:Integer;
  FileImage : String;
  var excel1: OleVariant;
begin

  FileImage := ExtractFilePath(Application.ExeName)+'\Chart.bmp';

i:=0;
colora:=1;



Libro := Excel.Workbooks.Add(Null, 0);
Hoja  := Libro.Sheets[1] as _WORKSHEET;


//titulo
i:=i+1;


        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;


Hoja.Cells.Item[i,1]:='Totales';
Hoja.Cells.Item[i,2]:='Actividades Realizadas';



//Insertamos todos los registros al excel  y en dbgrid 1
  with table do
    begin
    first;
      while not EOF Do
        begin
        i:=i+1;
        Hoja.Cells.Item[i,1]:=DBGrid1.Fields[0].AsString;
        Hoja.Cells.Item[i,2]:=DBGrid1.Fields[1].AsString;

        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;

//        Hoja.Cells.Item[i,3]:=DBGrid1.Fields[2].AsString;
        Next;
   end;//while
end;//with





//Luego insertamos el total

        i:=i+1;
        Hoja.Cells.Item[i,1]:= 'Total ';
//      Hoja.Cells.Item[i,2]:= total.Caption;


//Excel.Visible[0] := true;

 excel1 := GetActiveOleObject('Excel.Application');
 excel1.Workbooks.add.worksheets[1].shapes.addpicture(ExtractFilePath(Application.ExeName)+'\Chart.bmp', False, True, 6, 6, 666, 666);
 excel1.visible := True;


ShowMessage('Exportado con Exito!');

end;

Gracias de antemano.

Saludos
__________________
Cristo te ama, ven a d él, ya k te espera con los brazos abiertos. Dios te bendiga mucho
Responder Con Cita
  #2  
Antiguo 20-01-2015
Avatar de jeremiselxi
jeremiselxi jeremiselxi is offline
Miembro
 
Registrado: ago 2008
Posts: 199
Poder: 16
jeremiselxi Va por buen camino
Me respondo yo mismo:

Adjunto el código:

Código Delphi [-]

procedure TForm1.ExportaraexcelClick(Sender: TObject);
var
  Libro : _WORKBOOK;
  Hoja  : _WORKSHEET;
  i,colora:Integer;
  FileImage : String;
  var excel1: OleVariant;
begin

  FileImage := ExtractFilePath(Application.ExeName)+'\Chart.bmp';

i:=0;
colora:=1;



Libro := Excel.Workbooks.Add(Null, 0);
Hoja  := Libro.Sheets[1] as _WORKSHEET;


//titulo
i:=i+1;


        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;


Hoja.Cells.Item[i,1]:='Totales';
Hoja.Cells.Item[i,2]:='Actividades Realizadas';



//Insertamos todos los registros al excel  y en dbgrid 1
  with table do
    begin
    first;
      while not EOF Do
        begin
        i:=i+1;
        Hoja.Cells.Item[i,1]:=DBGrid1.Fields[0].AsString;
        Hoja.Cells.Item[i,2]:=DBGrid1.Fields[1].AsString;

        if colora=1 then
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
          colora:= colora +1;
        end
        else
        begin
          Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
          colora:= colora -1;
        end;

//        Hoja.Cells.Item[i,3]:=DBGrid1.Fields[2].AsString;
        Next;
   end;//while
end;//with





//Luego insertamos el total

        i:=i+1;
        Hoja.Cells.Item[i,1]:= 'Total ';
//      Hoja.Cells.Item[i,2]:= total.Caption;


//Excel.Visible[0] := true;

 excel1 := GetActiveOleObject('Excel.Application');

 excel1.ActiveSheet.Cells[3, 3].Select;
 excel1.ActiveSheet.Pictures.Insert(FileImage);

 excel1.visible := True;


ShowMessage('Exportado con Exito!');

end;
__________________
Cristo te ama, ven a d él, ya k te espera con los brazos abiertos. Dios te bendiga mucho
Responder Con Cita
Respuesta



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
Exportar a Excel desde builder 6.0 damian2000 C++ Builder 9 22-06-2016 18:18:56
Exportar a excel desde CodeTyphon vroa74 Lazarus, FreePascal, Kylix, etc. 2 10-09-2013 06:59:17
exportar a excel desde php halizia PHP 22 29-11-2006 09:20:37
Exportar desde BDE a Excel tamara Servers 1 03-10-2003 23:05:02
Exportar desde Tabla BDE a Excel tamara Conexión con bases de datos 1 03-10-2003 18:20:03


La franja horaria es GMT +2. Ahora son las 12:14:56.


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