Author: William Gerbert
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.
1 uses2 OleAuto; // Delphi 33 ComObj; // Delphi 54 5 var6 vExcel: variant;
7 8 procedure TForm1.Button1Click(Sender: TObject);
9 begin10 vExcel := CreateOleObject('Excel.Application');
11 vExcel.Workbooks.Add;
12 vExcel.ActiveWorkbook.Worksheets(1).Range('A1').Value := 'Hello World';
13 vExcel.Visible := True;
14 end;
15 16 procedure TForm1.FormDestroy(Sender: TObject);
17 begin18 ifnot VarIsEmpty(vExcel) then19 vExcel.Quit;
20 end;