Ver Mensaje Individual
  #3  
Antiguo 28-07-2003
Avatar de jhonny
jhonny jhonny is offline
Jhonny Suárez
 
Registrado: may 2003
Ubicación: Colombia
Posts: 7.058
Reputación: 30
jhonny Va camino a la famajhonny Va camino a la fama
Me parece muy comodo usar un componente pero este procedimiento tambien te servira...

Código:
procedure excel(EXQuery : TDataSet ;NoCampos :integer);
var
   XL, XArr: Variant;
   i : Integer;
   j : Integer;
begin
     EXQuery.First;
     XArr:=VarArrayCreate([1,NoCampos],varVariant);
     try
        XL := GetActiveOleObject('Excel.Application');
     except
       XL:=CreateOLEObject('Excel.Application');     // Ole object creation
     end;
     XL.WorkBooks.add;
     XL.visible:=true;

     j := 2;
     i := 0;
     while i < NoCampos do
     begin
        XArr[i+1]:=EXQuery.Fields[i].DisplayLabel;
        i := i+1;
        EXQuery.Next;
     end;
     XL.Range['A'+IntToStr(j),
     CHR(64+NoCampos)+IntToStr(j)].Value := XArr;

     XL.Range['A1',CHR(64+NoCampos)+IntToStr(j)].select;
     XL.Selection.Font.Name:='Times New Roman';
     XL.Selection.Font.Size:=10;
     XL.Selection.Font.color := clblue;
     XL.Selection.Font.bold := true;
     XL.Selection.Font.underline := true;


     j := 3;
     EXQuery.First;
     while not EXQuery.Eof do begin
           i:=1;
           while i<=NoCampos do begin
                 XArr[i] := EXQuery.Fields[i-1].Value;
                 i := i+1;
           end;
           XL.Range['A'+IntToStr(j),
	           CHR(64+NoCampos)+IntToStr(j)].Value := XArr;
           EXQuery.Next;
           j := j + 1;
     end;
     XL.Range['A1',CHR(64+NoCampos)+IntToStr(j)].select;
     XL.selection.Columns.AutoFit;
     XL.Range['A1','A1'].select;
end;
Bueno por lo menos a mi si que me ha servido, espero que a voz tambien
__________________
Lecciones de mi Madre. Tema: modificación del comportamiento, "Pará de actuar como tu padre!"

http://www.purodelphi.com/
http://www.nosolodelphi.com/
Responder Con Cita