C
cl_zhx
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把Excel表中的多行数据导入到StringGrid中(如果Excel表中第一列数据为空时结束
导入我的程序代码如下但在 while sheet.cells[i,1]<>'' do 行有错误请指点多谢)
procedure TForm1.Button1Click(Sender: TObject);
var
filename:variant;
sheet:variant;
i:integer;
begin
try
ExcelApplication1.Connect ;
opendialog1.Execute ;
filename:=opendialog1.FileName ;
ExcelApplication1.Visible [0]:=false;
ExcelApplication1.Workbooks.Add(filename,0);
sheet:= ExcelApplication1.Workbooks[1].Worksheets [1];
i:=1
while sheet.cells[i,1]<>'' do //
begin
SGrid1.Cells [0,i]:=sheet.cells[i,1];
SGrid1.Cells [1,i]:=sheet.cells[i,2];
SGrid1.Cells [2,i]:=sheet.cells[i,3];
SGrid1.Cells [3,i]:=sheet.cells[i,4];
i:=i+1;
end;
finally
end;
ExcelApplication1.Quit ;
ExcelApplication1.Destroy ;
end;
end.
导入我的程序代码如下但在 while sheet.cells[i,1]<>'' do 行有错误请指点多谢)
procedure TForm1.Button1Click(Sender: TObject);
var
filename:variant;
sheet:variant;
i:integer;
begin
try
ExcelApplication1.Connect ;
opendialog1.Execute ;
filename:=opendialog1.FileName ;
ExcelApplication1.Visible [0]:=false;
ExcelApplication1.Workbooks.Add(filename,0);
sheet:= ExcelApplication1.Workbooks[1].Worksheets [1];
i:=1
while sheet.cells[i,1]<>'' do //
begin
SGrid1.Cells [0,i]:=sheet.cells[i,1];
SGrid1.Cells [1,i]:=sheet.cells[i,2];
SGrid1.Cells [2,i]:=sheet.cells[i,3];
SGrid1.Cells [3,i]:=sheet.cells[i,4];
i:=i+1;
end;
finally
end;
ExcelApplication1.Quit ;
ExcelApplication1.Destroy ;
end;
end.