我有一段代码,导出我查出的数据,但格式有点问题。
这是我导出来的格式:
864059013460100320031220 3167 6699400030 0027083084000005
864059881553100120031220 13558 6699400030 0027086321000020
518476420000664920031220 127546 6699400030 0027081005000025
518476420010150720031220 833 6699400030 0027085061000027
518476420017236720031220 379534 6699400030 0027086243000029
518476420022406920031220 18994 6699400030 0027080705000034
518475420005029120031220 45078 6699400030 0027086044000041
我想导出这种格式:
864059013460100320031220 3167 6699400030 0027083084000005
864059881553100120031220 13558 6699400030 0027086321000020
518476420000664920031220 127546 6699400030 0027081005000025
518476420010150720031220 833 6699400030 0027085061000027
518476420017236720031220 379534 6699400030 0027086243000029
518476420022406920031220 18994 6699400030 0027080705000034
518475420005029120031220 45078 6699400030 0027086044000041
各列数据向右对齐这是我导出的代码,请各位高手斧正
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
testfile:textfile;
begin
ADOquery1.open;
ADOquery1.First;
if savedialog1.Execute then begin
assignfile(testfile,savedialog1.FileName+'.txt');
rewrite(testfile);
while not ADOquery1.Eof do
begin
writeln(testfile,adoquery1.fields[0].asstring+' '+trim(adoquery1.fields[1].asstring)+' '+trim(adoquery1.fields[2].asstring)+' '+trim(adoquery1.fields[3].asstring));
ADOquery1.Next;
end;
closefile(testfile);
end;
end;
这是我导出来的格式:
864059013460100320031220 3167 6699400030 0027083084000005
864059881553100120031220 13558 6699400030 0027086321000020
518476420000664920031220 127546 6699400030 0027081005000025
518476420010150720031220 833 6699400030 0027085061000027
518476420017236720031220 379534 6699400030 0027086243000029
518476420022406920031220 18994 6699400030 0027080705000034
518475420005029120031220 45078 6699400030 0027086044000041
我想导出这种格式:
864059013460100320031220 3167 6699400030 0027083084000005
864059881553100120031220 13558 6699400030 0027086321000020
518476420000664920031220 127546 6699400030 0027081005000025
518476420010150720031220 833 6699400030 0027085061000027
518476420017236720031220 379534 6699400030 0027086243000029
518476420022406920031220 18994 6699400030 0027080705000034
518475420005029120031220 45078 6699400030 0027086044000041
各列数据向右对齐这是我导出的代码,请各位高手斧正
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
testfile:textfile;
begin
ADOquery1.open;
ADOquery1.First;
if savedialog1.Execute then begin
assignfile(testfile,savedialog1.FileName+'.txt');
rewrite(testfile);
while not ADOquery1.Eof do
begin
writeln(testfile,adoquery1.fields[0].asstring+' '+trim(adoquery1.fields[1].asstring)+' '+trim(adoquery1.fields[2].asstring)+' '+trim(adoquery1.fields[3].asstring));
ADOquery1.Next;
end;
closefile(testfile);
end;
end;
writeln(testfile,adoquery1.fields[0].asstring +
+Format('x=%3d', [adoquery1.fields[1].asInteger]) + //第二列数据
' '+trim(adoquery1.fields[2].asstring)+' '+trim(adoquery1.fields[3].asstring));
writeln(testfile,adoquery1.fields[0].asstring +
+Format('x=%10d', [adoquery1.fields[1].asInteger]) +
//第二列数据,格式化为长度10的字符串,实际需要多少长度自己调整
' '+trim(adoquery1.fields[2].asstring)+' '+trim(adoquery1.fields[3].asstring));