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
这句的时候就报错“无效的参数数目”,请问各位大侠,为什么??
... , 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
这句的时候就报错“无效的参数数目”,请问各位大侠,为什么??
在vba中不用Item,在delphi中得用,你自己再研究研究吧,
例如: range:=aExcelApp.range[aExcelApp.cells[1,1],aExcelApp.cells[20,1]];
StringGrid1.Cells[1,i]:=range.value;