procedure TForm1.Button1Click(Sender: TObject);//打印 var i,j:Longint; path,s1,s2,sall:string; sl:TStringList; begin sl:=TStringList.Create ; path:=extractfilepath(application.ExeName )+'test.txt'; if fileexists(path) then deletefile(path); sall:='; for i:=1 to sg1.RowCount -1 do begin//2 for j:=1 to sg1.colCount -1 do begin//1 sall:=sall+sg1.Cells[j,i]+stringofchar(' ',10);//换行回车 end;//1 sall:=sall+#13#10;//换行回车 end;//2 sl.Clear ; sl.Add(sall); sl.SaveToFile(path); end;
procedure TForm1.sg1GetEditText(Sender: TObject; ACol, ARow: Integer; var Value: String); var m1,m2:Longint; s1,s2:string; begin { s1:=value; m1:=length(s1); if m1<8 then begin m2:=8-m1; value:=stringofchar('0',m2)+value; end; } end;
procedure TForm1.sg1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); var m1,m2:Longint; s1,s2:string; begin tts1:=tts1+sg1.Cells [acol,arow]; m1:=length(s1); if m1>=8 then begin m2:=m1-8; s2:=copy(s1,m2+1,m1); sg1.Cells [acol,arow]:= '; sg1.Cells [acol,arow]:=s2; exit; end; if m1<8 then begin m2:=8-m1; s2:=stringofchar('0',m2)+sg1.Cells [acol,arow]; sg1.Cells [acol,arow]:=s2; end; end;
procedure TForm1.sg1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin tts1:='; end;
procedure TfrmLocale.Button2Click(Sender: TObject); var i,J,K:Integer; strLine,strcell:string; fileHandle:THandle; fileName:textfile; filestr:string; begin filestr:='c:\test.txt'; if fileExists(filestr)=false then begin fileHandle:=FileCreate(filestr); fileClose(FileHandle); end;
assignFile(FileName,Filestr); Rewrite(fileName); for K:=1 to stringGrid1.RowCount - 1 do begin strLine:='; for I:=1 to stringGrid1.ColCount -1 do begin strcell :=stringGrid1.Cells[i,K]; for J:=length(strcell) to 8 do strcell :=strcell + ' '; strLine :=strLine + strcell;//stringGrid1.Cells[i,1]; end; writeLn(fileName,strLine); end; closeFile(FileName); end;
----------------------------------------------
-
procedure TfrmLocale.StringGrid1KeyPress(Sender: TObject; var Key: Char); begin if (ord(key) <48) or (ord(key)>57) then begin showmessage('error'); key:=chr(0); end; end;
----------------------------------------------
-