Handle Excel through OLE Automation (Views: 31)
Problem/Question/Abstract: Handle Excel through OLE Automation Answer: The example below shows how to create and control an embedded Excel object. In case of Delphi 3, you need to use unit OleAuto, in Delphi 5 you have to use ComObj instead. A good additional source is here. uses OleAuto; // Delphi 3 ComObj; // Delphi 5 var vExcel: variant; procedure TForm1.Button1Click(Sender: TObject); begin vExcel := CreateOleObject('Excel.Application'); vExcel.Workbooks.Add; vExcel.ActiveWorkbook.Worksheets(1).Range('A1').Value := 'Hello World'; vExcel.Visible := True; end; procedure TForm1.FormDestroy(Sender: TObject); begin if not VarIsEmpty(vExcel) then vExcel.Quit; end; |