
读取execl数据在5个标签显示,ediit编辑框中录入对应的数据,当最后一个录入完毕后,数据要更新,更新要怎么赋值,试了多种方式,最后思路都弄乱了,代码传上,帮改一下:
procedure TForm1.btn1Click(Sender: TObject);
var
xls:TXLSReadWriteII5;
n,i,j,y:Integer;
cour :array of Integer;
begin
XLS := TXLSReadWriteII5.Create(Self);
XLS.LoadFromFile(ExtractFilePath(paramstr(0)) + '..\data\数据.xlsx');
try
XLS.Clear;
xls.Read;
lbl1.Caption:=IntToStr(xls.Sheets[1].LastRow ); //总数
for j := 1 to StrToInt(lbledt1.Text) do //
begin
for i:=1 to 5 do
begin
(FindComponent('Lblsc'+inttostr(i)) as TLabel).Caption := xls.Sheets[1].AsString[i-1, 1]; //标签用数组读取
end;
edt1.MaxLength:=Length(lblsc1.Caption);edt2.MaxLength:=Length(lblsc2.Caption);edt3.MaxLength:=Length(lblsc3.Caption);
edt4.MaxLength:=Length(lblsc4.Caption);edt5.MaxLength:=Length(lblsc5.Caption); //设置输入区对应长度
// cour[y]:= j+1 ; ?这赋值有问题,不知要怎么弄
end
finally
XLS.Free;
end;
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if ((Key>=#32) and (Key<#255)) and (not (((Key >= '0') and (Key <= '9')) or (Key = '.') or (Key = '-'))) then // 只能输入数字,小数点,负号
begin
key := #0;
end;
end;
procedure TForm1.edt1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Length(edt1.Text) >= Length(lblsc1.Caption)) then edt2.SetFocus;
end;
.........
procedure TForm1.edt5KeyPress(Sender: TObject; var Key: Char);
begin
if ((Key>=#32) and (Key<#255)) and (not (((Key >= '0') and (Key <= '9')) or (Key = '.') or (Key = '-'))) then // 只能输入数字,小数点,负号
begin
key := #0;
end;
end;
procedure TForm1.edt5KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Length(edt5.Text) >= Length(lblsc5.Caption)) then
begin
edt1.Text:='';
edt2.Text:='';
edt3.Text:='';
edt4.Text:='';
edt5.Text:='';
edt1.SetFocus
end;
end;