Código
procedure pExportarDadosExcel(Query : TQuery);
var
Excel : Variant;
Linha, i : Integer;
begin
if not Query.IsEmpty then
begin
Query.First;
Excel := CreateOleObject('Excel.Application');
Excel.Visible := True;
Excel.Workbooks.Add;
Linha := 1;
for i := 0 to Query.FieldCount - 1 do
Excel.WorkBooks[1].Sheets[1].Cells[Linha,i+1] := Query.Fields[i].DisplayName;
Linha := 2;
While not Query.Eof do
Begin
for i := 0 to Query.FieldCount - 1 do
Excel.WorkBooks[1].Sheets[1].Cells[Linha,i+1] := Query.Fields[i].Value;
Query.Next;
Linha:=Linha+1;
end;
end;
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009