L
lyq2276959
Unregistered / Unconfirmed
GUEST, unregistred user!
将其输出为Text文件或csv文件,用excell打开时选择相应的类型即可
最好为text文件类型,否则数据库中若有身份证号或其它数值较大的字段,
则显示不正常。
procedure TForm1.Button2Click(Sender: TObject);
var f:textfile;
fs,str:string;
i,j:integer;
begin
table1.DisableControls;
if not table1.IsEmpty then
begin
if savedialog1.execute then
begin
fs:=savedialog1.filename;
assignfile(f,fs);
rewrite(f);
for i:=0 to table1.FieldCount-1 do
begin
if table1.Fields.Fields.Visible then
begin
str:='"'+table1.Fields.Displaylabel+'"';
write(f,str);
write(f,',');
end;
end;
writeln(f,'');
table1.first;
for i:=0 to table1.RecordCount-1 do
begin
for j:=0 to table1.FieldCount-1 do
begin
if table1.Fields.Fields[j].Visible then
begin
str:='"'+table1.Fields[j].Displaytext+'"';
write(f,str);
write(f,',');
end;
end;
writeln(f,'');
table1.next;
end;
closefile(f);
end;
end
else
begin
showmessage('数据库中无记录');
end;
showmessage('数据完成转换');
table1.First;
table1.EnableControls;
end;
最好为text文件类型,否则数据库中若有身份证号或其它数值较大的字段,
则显示不正常。
procedure TForm1.Button2Click(Sender: TObject);
var f:textfile;
fs,str:string;
i,j:integer;
begin
table1.DisableControls;
if not table1.IsEmpty then
begin
if savedialog1.execute then
begin
fs:=savedialog1.filename;
assignfile(f,fs);
rewrite(f);
for i:=0 to table1.FieldCount-1 do
begin
if table1.Fields.Fields.Visible then
begin
str:='"'+table1.Fields.Displaylabel+'"';
write(f,str);
write(f,',');
end;
end;
writeln(f,'');
table1.first;
for i:=0 to table1.RecordCount-1 do
begin
for j:=0 to table1.FieldCount-1 do
begin
if table1.Fields.Fields[j].Visible then
begin
str:='"'+table1.Fields[j].Displaytext+'"';
write(f,str);
write(f,',');
end;
end;
writeln(f,'');
table1.next;
end;
closefile(f);
end;
end
else
begin
showmessage('数据库中无记录');
end;
showmessage('数据完成转换');
table1.First;
table1.EnableControls;
end;