读取Excel的Items[x,y]内容的问题。100分
uses
... , ComObj, ...
var
aExcelApp: Variant;
aRowCount, aIndex: Integer;
begin
aExcelApp := CreateOleObject( 'Excel.Application' );
aExcelApp.Visible:= True;
//aName是Excel文件名,等于OpenDialog1.FileName
aExcelApp.WorkBooks.Open(aName);
aExcelApp.WorkSheets[1].Activate;
//运行到下面这句就报错“无效的参数数目”
aRowCount:= aExcelApp.WorkSheets[1].UsedRange[1].Rows.Count;
SGrid1.RowCount:= aRowCount;
for aIndex:=2 to aRowCount-1 do
StringGrid1.Cells[2,aIndex]:= aExcelApp.WorkSheets[1].Cells.Item[aIndex,2].Value;
aExcelApp.WorkBooks.Close;
aExcelApp.Quit;
end;
这段代码是用来将Excel的第二列的数据取到StringGrid1中,但是在运行
aRowCount:= aExcelApp.WorkSheets[1].UsedRange[1].Rows.Count
这句的时候就报错“无效的参数数目”,请问各位大侠,为什么??