How to use native spreadsheet functions in google apps script?

半城伤御伤魂 提交于 2019-12-09 15:11:59

问题


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?


回答1:


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().




回答2:


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)");



回答3:


Also might be good to refer to this article about using Javascript objects to read and write to cells. I can't think of any good reason for using functions in VBA or Apps Script unless they are doing so indirectly through reading a cell value. https://developers.google.com/apps-script/guides/sheets#reading



来源:https://stackoverflow.com/questions/25234912/how-to-use-native-spreadsheet-functions-in-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!