In short, the contents of Excel when executing the form should be loaded into a specially prepared SG. In other forms of the program it works fine. And one is not. Pressing the button leads to the error: "Project New.exe raised exception class EVariantInvalidOpErroe with message 'Invalid variant operation'". I decided to bring some of the problem code to a new project (or is there a problem elsewhere?) But when I compile, I get the same error. Code:

var Form1: TForm1; excelname:variant; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var ExcelLocation:string; m,stroka:integer; begin GetDir(0,ExcelLocation); excelname.workbooks.Open(ExcelLocation+'/3.xlsx'); m:=1; for m:=1 to stroka-1 do begin stringgrid1.Cells[1,m]:=excelname.range['A'+inttostr(m+1)]; stringgrid1.Cells[2,m]:=excelname.range['B'+inttostr(m+1)]; stringgrid1.Cells[3,m]:=excelname.range['C'+inttostr(m+1)]; end; end; 

    1 answer 1

     нужно создать сперва объект ексела Excelname := CreateOleObject('Excel.Application'); потом попробуйте открыть: excelname.workbooks.Open(ExcelLocation+'/3.xlsx'); ..................................