SpreadJS Documentation > Formula Reference > Formula Overview > Cell References in a Formula > Relative and Absolute |
A relative cell reference is a reference to a cell relative to the position of the cell with the formula. An absolute reference is a cell reference that always refers to a cell by its exact location in the sheet and not with reference to the present cell.
Relative references automatically adjust when you copy them and absolute references do not. The widget can use absolute or relative cell references. You can define the cell reference style for each sheet by using the ReferenceStyle property. The formula does not support a range reference that contains both absolute and relative row or column references. In other words, the start and end rows in a range reference have to match (both absolute or both relative). The following table contains examples of valid relative cell references in formulas.
Function | Description |
---|---|
SUM(A1:A10) | Sums rows 1 through 10 in the first column |
PI( )*C6 | Multiplies pi times the value in cell C6 |
(A1 + B1) * C1 | Adds the values in the first two cells and multiplies the result by the value in the third cell |
IF(A1>5, A1*2, A1*3) | Checks if the contents of cell A1 are greater than 5, and if so, multiplies the contents of cell A1 by 2, or else multiplies the contents of cell A1 by 3 |
For A1 notation, use a dollar sign ($) preceding the row or column (or both) to indicate an absolute reference. For example
$A$1 | absolute first column, absolute first row |
$A1 | absolute first column, relative row plus one |
A$1 | relative column plus one, absolute first row |
A1 | relative column plus one, relative row plus one |
For R1C1 notation, use brackets [ ] around the row or column number (or both) to indicate a relative reference. For example
R1C1 | absolute first row, absolute first column |
R1C[1] | absolute first row, relative column plus one |
R[1]C1 | relative row plus one, absolute first column |
R[1]C[1] | relative row plus one, relative column plus one |
R[-1]C[-1] | relative row minus one, relative column minus one |
In this notation, the number inside the brackets is an offset from the current cell. This number may be a negative or positive integer or zero. Leaving off the offset entirely is short hand way of indicating a zero offset. So,
RC2 is equivalent to R[0]C2
R[3]C is equivalent to R[3]C[0]