怎么样才可以把Access数据库一表中指定范围的数据写入一个规格格式的a.txt文件(50分)

  • 主题发起人 主题发起人 ygj971201
  • 开始时间 开始时间
Y

ygj971201

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样才可以把Access数据库一表中指定范围的数据写入一个规格格式的a.txt文件
格式如下:
MIPT8535 T 2100950006 1886.0000
MIPT8535 T 2100950007 2829.0000
MIPT0930 T 2100725012 952.0000
MIPT9862 T 2100725011 603.0000
MIPT7378 T 2100725010 333.0000
 
应该不难
用SQL筛选数据

然后自己往文本里写啊,虽然笨了些,可是管用
 
给个做法好吗
 
function dbftotxt(tablename:string;const fieldlist:array of string;txtfile:string):boolean;
var
i:integer;
ts:tstringlist;
s:string;
tt:ttable;
begin
ts:=tstringlist.Create ;
tt:=ttable.Create(nil);
try
tt.tablename:= tablename;
tt.Open ;
tt.First;
while not tt.Eof do begin
s:='';
for i:=low(fieldlist) to high(fieldlist) do begin
if tt.FieldByName(fieldlist).DataType=ftstring then begin
if i=high(fieldlist) then s:=s+'"'+tt.Fields.FieldByName(fieldlist).AsString +'"';
if i<high(fieldlist) then s:=s+'"'+tt.Fields.FieldByName(fieldlist).AsString +'",';
end;
if tt.FieldByName(fieldlist).DataType=ftfloat then begin
if i=high(fieldlist) then s:=s+floattostr(tt.Fields.FieldByName(fieldlist).Asfloat);
if i<high(fieldlist) then s:=s+floattostr(tt.Fields.FieldByName(fieldlist).Asfloat)+',';
end;
if tt.FieldByName(fieldlist).DataType=ftinteger then begin
if i=high(fieldlist) then s:=s+inttostr(tt.Fields.FieldByName(fieldlist).Asinteger);
if i<high(fieldlist) then s:=s+inttostr(tt.Fields.FieldByName(fieldlist).Asinteger)+',';
end;
end;
ts.Add(s);
tt.Next ;
end;
ts.SaveToFile(txtfile);
ts.Free ;
tt.Free ;
result:=true;
except
result:=false;
end;
end;

这个是我现在用的一个函数,是DBF转TXT的,你可以参考一下
 
Select * Into [Text;Database=c:/temp].aaaa.txt from table
这样就可以了,如果你向设计格式,在odbc里面数据源里面查看format就是了。
 

Similar threads

S
回复
0
查看
841
SUNSTONE的Delphi笔记
S
S
回复
0
查看
823
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部