HotXLS-dokumentation

Formula egenskab

Returnerer or sets the cell's Formula. Read/write Variant

Syntaks

property Formula: Variant;

Bemærkninger

If the cell contains a constant, this property returns the constant.
Indeholder cellen en formel, returnerer egenskaben Formula formlen som en streng (inklusive lighedstegnet)
Er området et én- eller todimensionelt område, kan du sætte Formula til et Variant-array med de samme dimensioner
Similarly, the Formula property returns the Variant Array.
Sætter man Formula for et område med flere celler, udfyldes alle celler i området med formlen

HotXLS's Formula compiler use the semicolon sign instead of comma as the funktion argument separator
book.Sheets[1].Cells[2,3].Formula := '=IF(A1>100;A1*B1;A1*B2)';

Eksempel

Eksemplet sætter Formula for celle A2 og henter resultatet af formlen i variablen Val

With Workbook.Sheets[1] do begin
  Cells[1,1].Value := 100;
  Cells[2,1].Formula := '=IF(A1>70;A1/2;A1)';
  Val := Cells[2,1].Value;  //Val = 50
end;
This example copies the Formulas from A1:F1 range to A2:F2 range

With Workbook.Sheets[1] do begin
  Range['A2', 'F2'].Formula := Range['A1', 'F1'].Formula;
end;
This example is the same to previous

With Workbook.Sheets[1].Range['A1', 'F1'] do
    Offset[1,0].Formula := Formula;