与 COM 交互

动态类型

uses System.Win.ComObj;

var
  Excel, Sheet: Variant;
begin
  //create simple Excel table
  Excel := CreateOleObject(
    'Excel.Application');
  Excel.Workbooks.Add;

  Sheet := Excel.ActiveSheet;
  Sheet.Cells[1, 1] := 3;
  Sheet.Cells[2, 1] := 5;
  Sheet.Cells[3, 1] :=
    '=sum(R[-2]C[0]:R[-1]C[0])';

  //all calls are late bound: the
  //names are resolved by IDispatch
  Excel.Visible := True;
end.