这个容易不过,文本要有规律就可以了,不如字段间用TAB隔开,
然后把它读入就可以了,不过也可以用一个小技巧,就是将
这样有规律的文件作为Excel来对待,用Delphi的Server上的
关于excel的控键来读和写,具体的代码我有不过不在这个计算机上,
有空我贴上来。
然后把它读入就可以了,不过也可以用一个小技巧,就是将
这样有规律的文件作为Excel来对待,用Delphi的Server上的
关于excel的控键来读和写,具体的代码我有不过不在这个计算机上,
有空我贴上来。
/* 输出到文本文件 */
var
i,j,k:integer;
f2 :textfile;
aa:string;
begin
j:=query1.Fields.Count;
k:=query1.RecordCount;
if SaveDialog1.Execute then
AssignFile(F2, SaveDialog1.Filename);
Rewrite(F2);
query1.First;
for k:=k downto 1 do
begin
for i:=0 to j-1 do
begin
aa:=aa+'#'+query1.Fields.Fields[i].asstring;
end;
writeln(f2,aa);
query1.Next;
aa:='';
end;
CloseFile(F2);
while not eof(F) do begin
readln(strtmp,F);
for i:=1 to fieldNum do begin
position:=pos('#',strtmp);
otherstr:=copy(strtmp,1,position-1); //取出一个字段值
delete(strtmp,position); //从串删除该字段值,使后面的字段都顺序向前移
query1.Fields.Fileds[i].value:=otherstr;
query1.insert;
end; //
end;
procedure TForm1.Button2Click(Sender: TObject);
var f : textfile;
i,position : integer;
strtmp,otherstr,filename : string;
begin FileName := GetCurrentDir + '\fixempo.txt';
If FileExists(FileName) then
begin
AssignFile(F,FileName);
ReSet(F); table1.open;
while not eof(F) do
begin
readln(F,strtmp);
for i:=1 to 2 do
begin
position:=pos('#',strtmp);
otherstr:=copy(strtmp,1,position-1); //取出一个字段值
delete(strtmp,position,length(Otherstr)); //从串删除该字段值,使后面的字段都顺序向前移 table1.edit;
table1.Fields.Fields[i].value:=otherstr;
table1.post;
end; //
end;
end;
end;
var f : textfile;
i,position : integer;
strtmp,s,filename : string;
begin
FileName := GetCurrentDir + '\fixempo.txt';
If FileExists(FileName) then
begin
query1.close;
query1.sql.Clear;
query1.sql.Add('insert into FixEmpo(empoName,departname)');
query1.sql.Add('values(:empo,:depart)');
AssignFile(F,FileName);
ReSet(F); while not eof(F) do
begin
readln(F,strtmp);
while pos('#',strtmp) <> 0 do
begin
for i:= 1 to 2 do
begin
position:=pos('#',strtmp);
s := copy(strtmp,1,position-1); //取出一个字段值
Delete(strtmp,1,position); //从串删除该字段值,使后面的字段都顺序向前移
query1.Fields.Fields[i].value:= S;
query1.Insert;
end;
end;
end;
end;
end;