How to use native spreadsheet functions in google apps script?

user3347814 picture user3347814 · Aug 11, 2014 · Viewed 10.4k times · Source

Is it possible to use native spreadsheet functions such as sum() or today() in google apps script, when writing code for google Spreadsheet? If so, how do I do it?

Answer

AshClarke picture AshClarke · Aug 11, 2014

https://developers.google.com/apps-script/reference/spreadsheet/range#setFormula(String)

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var cell = sheet.getRange("B5");
cell.setFormula("=SUM(B3:B4)");