把数据库的内容转换到EXCEL:
procedure TForm3.BitBtn2Click(Sender: TObject);
var f:textfile;
fs,str:string;
i,j,k:integer;
begin
if not query1.IsEmpty then
begin
if savedialog1.execute then
begin
fs:=savedialog1.filename;
assignfile(f,fs);
rewrite(f);
for i:=0 to query1.FieldCount-1 do
begin
begin
str:=query1.Fields.Displaylabel;
for j:=query1.Fields.datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
end;
writeln(f,'');
query1.first;
for i:=0 to query1.RecordCount-1 do
begin
for j:=0 to query1.FieldCount-1 do
begin
str:=query1.Fields[j].Displaytext;
for k:=query1.Fields[j].datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
writeln(f,'');
query1.next;
end;
filestr1:=fs;
closefile(f);
end;
end
else
begin
showmessage('empty table');
end;
query1.first;
end;
保存成excel类型的文件