这个容易不过,文本要有规律就可以了,不如字段间用TAB隔开,
然后把它读入就可以了,不过也可以用一个小技巧,就是将
这样有规律的文件作为Excel来对待,用Delphi的Server上的
关于excel的控键来读和写,具体的代码我有不过不在这个计算机上,
有空我贴上来。

解决方案 »

  1.   

    将query(BDE)中的内容输出到文本文件,当然是有规律的了,导出的代码如下所示。导入俺还有问题,请详细点!!!!!!!!
    /* 输出到文本文件 */
    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);
      

  2.   

    这是伪代码,你自己改成DELPHI吧,很久没写了,所以语法可能不对。  先打开文件和连接数据库,  
     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;
      

  3.   

    NewStarSE(新星):你的代码我试了一下,还有很多问题,我写的代码如下所示,很感谢你的指导,希望你能试试,将最新结果E-MAIL给我:[email protected]
    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;
      

  4.   

    从文本读入库时,出现错误,请哪位大虾指点迷津!!!!!!!!!!!!!!!!!procedure TForm1.Button2Click(Sender: TObject);
    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;