我正在使用此代码加载仅包含数字的 Excel 电子表格。但是将整个文件加载到 . 文件中需要很长时间stringgrid
,有人知道更快的方法吗?
procedure sh1(SheetIndex:integer);
Var
Xlapp1, Sheet:Variant ;
MaxRow, MaxCol,X, Y:integer ;
str:string;
begin
Str:=trim(form2.OpenDialog1.FileName);
XLApp1 := createoleobject('excel.application');
XLApp1.Workbooks.open(Str) ;
Sheet := XLApp1.WorkSheets[SheetIndex] ;
MaxRow := Sheet.Usedrange.EntireRow.count ;
MaxCol := sheet.Usedrange.EntireColumn.count;
form2.stringgrid1.RowCount:=maxRow+1;
form2.StringGrid1.ColCount:=maxCol+1;
for x:=1 to maxCol do
for y:=1 to maxRow do
form2.stringgrid1.Cells[x,y]:=sheet.cells.item[y,x].value;
XLApp1.Workbooks.close;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then begin
stringgrid1.Visible:=true;
sh1(1);
end;
end;