function Tform4.xlsORtxt(dataset:tdataset;filename:string):boolean;
var
f:textfile;
tempstr:string;
i,j:integer;
begin
try
dataset.DisableControls;
assignfile(f,filename);
rewrite(f);
dataset.First;
tempstr:='';
for i:=0 to dataset.FieldCount-1 do
tempstr:=tempstr+dataset.Fields.FieldName+#9;
writeln(f,tempstr);
for i:=0 to dataset.RecordCount-1 do
begin
tempstr:='';
for j:=0 to dataset.Fields.Count-1 do
tempstr:=tempstr+dataset.fields[j].AsString+#9;
writeln(f,tempstr);
dataset.Next;
end;
result:=true;
closefile(f);
except
closefile(f);
result:=false;
end;
end;
// 运用
procedure TForm4.BitBtn11Click(Sender: TObject);
begin
with savedialog1 do
if execute then
begin
if xlsORtxt(adoquery1,filename) then
showmessage('保存到:'+filename+'')
else
showmessage('error');
end;
end;
在savedialog1里设置格式 *.tet *.xls,*.doc 都可以!