不要用表,像Excel的可不可以?

解决方案 »

  1.   

    将StringGrid的数据先存入一个txt文件中
    用时再从txt中读出,不就OK了
      

  2.   

    怎样才能放数据存入一个TXT文件里,怎么才能取出来。
    能举个例了吗?
      

  3.   

    var
        FileName:TFileName;
        iFileHandle:Integer;
        Strop_id,Strop_type,Strop_table,Strop_man,Strop_date:Variant;    i,j,k:integer;
        iLen:array[0..4] of Integer;    iLenField:array[0..4] of integer;
        F: TextFile;
        strTmp:string;
    begin
    if   query3.active= true  then
      begin
        Strop_id:= ' 日志编号';
        Strop_type:= '日志创建类型';
        Strop_table:=  '日志创建表';
        Strop_man:= '日志创建员工';
        Strop_date:='日志创建日期';    iLen[0]:=18;
        iLen[1]:=18;
        iLen[2]:=20;
        iLen[3]:=20;
        iLen[4]:=20;    for j:=0 to 4 do
            for i:=0 to iLen[j]-10 do
            begin
                if j=0 then Strop_id:=Strop_id+' ';
                if j=1 then Strop_type:=Strop_type+' ';
                if j=2 then  Strop_table:= Strop_table+' ';
                if j=3 then Strop_man:=Strop_man+' ';
                if j=4 then  Strop_date:= Strop_date+' ';
              
            end;        strTmp:=Strop_id+Strop_type+Strop_table+Strop_man+ Strop_date;    SaveDialog1.Execute;
        FileName:=SaveDialog1.FileName+'.TXT';
        iFileHandle:=FileCreate(FileName);
        
        if iFileHandle<=0 then
        begin
            application.Messagebox(pchar('创建文件失败!'),'提示',mb_ok);
            exit;
        end;
        FileClose(iFileHandle);
        AssignFile(F,FileName);    ReWrite(F);
        Writeln(F,strTmp);    for i:=0 to Query3.RecordCount-1 do
        begin
           Strop_id:=Query3['op_id'];
           if Strop_id=Null THEN Strop_id:=' ';       Strop_type:=Query3['op_type'];
           if Strop_type=NULL THEN Strop_type:=' ';       Strop_table:=Query3['op_table'];
           if Strop_table=null then Strop_table:=' ';       strop_man:=Query3['op_man'];;
           if strop_man=NULL THEN Strop_man:=' ';       Strop_Date:=Query3['op_Date'];;
           if Strop_Date=null then Strop_Date:=' '
           else Strop_Date:=DateTimeToStr(Strop_Date);
                  iLenField[0]:=Length(strop_id);
           iLenField[1]:=Length( Strop_type);
           iLenField[2]:=Length( Strop_table);
           iLenField[3]:=Length(strop_man);
           iLenField[4]:=Length( Strop_Date);
            for j:=0 to 4 do
            for k:=0 to iLen[j]-iLenField[j]+1 do
            begin
                if j=0 then strop_id:=strop_id+' ';
                if j=1 then Strop_type:=Strop_type+' ';
                if j=2 then Strop_table:=Strop_table+' ';
                if j=3 then strop_man:=strop_man+' ';
                if j=4 then Strop_Date:=Strop_Date+' ';
                
            end;       strTmp:=strop_id+Strop_type+Strop_table+strop_man+Strop_Date;
           Writeln(F,strTmp);
             query3.next;     end;    closeFile(F);
      end;
    end;