unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComObj, StdCtrls, OleServer;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const IloscRzutow=10;
var
  ExlApp :Variant;
  n :Integer;
  wartosc :Double;
begin
ExlApp:=CreateOleObject('Excel.Application');
ExlApp.Visible:=True;
ExlApp.Workbooks.Add;

for n:=1 to IloscRzutow do
  begin
  ExlApp.ActiveSheet.Cells(n,1):=1+Int(Random(6));
  ExlApp.ActiveSheet.Cells(n,2):=1+Int(Random(6));
  ExlApp.ActiveSheet.Cells(n,3):='=A'+IntToStr(n)+'+B'+IntToStr(n);
  end;

ExlApp.ActiveSheet.Cells(IloscRzutow+1,1):='=SUM(A1:A'+IntToStr(IloscRzutow)+')';
ExlApp.ActiveSheet.Cells(IloscRzutow+1,2):='=SUM(B1:B'+IntToStr(IloscRzutow)+')';
ExlApp.ActiveSheet.Cells(IloscRzutow+1,3):='=SUM(C1:C'+IntToStr(IloscRzutow)+')';

ExlApp.ActiveSheet.Cells(IloscRzutow+2,1):='=AVERAGE(A1:A'+IntToStr(IloscRzutow)+')';
ExlApp.ActiveSheet.Cells(IloscRzutow+2,2):='=AVERAGE(B1:B'+IntToStr(IloscRzutow)+')';
ExlApp.ActiveSheet.Cells(IloscRzutow+2,3):='=AVERAGE(C1:C'+IntToStr(IloscRzutow)+')';
end;

end.
