Formulas can consist of values, operators, and functions. Data can be from other cells, a combination of data in another cell and hard-coded data (for example, A1 + 2), or simply hard-coded data (for example, SUM(4,5)). Formulas can perform mathematical operations, such as addition and multiplication, on values in other cells or they can compare values in other cells. Formulas can refer to cells in the same sheet by their absolute cell location or relative to the cell with the formula in it; they can refer to individual cells or a range of contiguous cells. If the values in the referenced cells change, then the value of the formula cell changes.
Formulas can be made up of:
cell references and cell ranges (notation indicating the address of cell or cells)
operators (that act on one or two values)
built-in functions (predefined formulas)
constants or array of constants (values you enter that do not change)
Use the setFormula method in the Worksheet class for specifying the formula. Returning the value of the formula property provides a string containing the written expression of the formula, for example, SUM(A1:B1).
sheet.getCell(2, 0).formula = "SUM(A1:A10)"
And if added in the cell by the end-user:
In this documentation, where examples are shown, the formula appears as:
SUM(3,4,5) gives the result 12
to express that the result of the formula would display the value of 12 in the cell.