Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use native spreadsheet functions in google apps script? [duplicate]

Tags:

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?

like image 787
user3347814 Avatar asked Aug 11 '14 02:08

user3347814


2 Answers

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)"); 
like image 141
AshClarke Avatar answered Nov 13 '22 16:11

AshClarke


Google Apps Script is JavaScript, spreadsheets functions are not available and using a workaround like setFormula followed by getValue is not only cumbersome but really slow and inefficient. You will be better inspired to use JavaScript and Google services to manipulate data taken from a spreadsheet and write the data back in one single setValues().

like image 45
Serge insas Avatar answered Nov 13 '22 17:11

Serge insas