Ver Mensaje Individual
  #2  
Antiguo 20-01-2015
Avatar de jeremiselxi
jeremiselxi jeremiselxi is offline
Miembro
 
Registrado: ago 2008
Posts: 199
Reputación: 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