Hier die Procedure um das Excel File zu erstellen ...
Delphi-Quellcode:
procedure TfrmXTMT.QueryToExcelFIle(
Query: TQuery; TargetFilename:
string; Header:boolean);
var
XFile:TStrings;
i:Integer;
str:
string;
begin
XFile := TStringList.Create;
with Query do
begin
str := '
';
if Header
then
begin
for i := 0
to Fields.Count-1
do
str := str + FieldDefs[i].
Name + #9;
XFile.Add(str);
end;
FindFirst;
while Found
do
begin
str := '
';
for i := 0
to Fields.Count-1
do
str := str + Fields[i].AsString + #9;
XFile.Add(str);
FindNext;
end;
end;
XFile.SaveToFile(TargetFilename);
XFile.Free;
end;