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.