I want to use a built-in function in a Google Apps script.
Something similar to VBA WorksheetFunction
How can I achieve that?
For example, how to include in the script:
var foo=DATEVALUE(mydate);
I want to use a built-in function in a Google Apps script.
Something similar to VBA WorksheetFunction
How can I achieve that?
For example, how to include in the script:
var foo=DATEVALUE(mydate);
I came across the same challenge.
My conceptual solution is the following:
Create a Spreadsheet with a cell (or cells) specifically devoted to the inputs of the built-in function, and another cell containing the built-in formula and it's result.
From a Spreadsheet embedded Google Apps Script, link to the spreadsheet and the two ranges: 1) through the first link feed the values into the input cell (or cells); 2) through the second link retrieve the result of the formula.
Every time you need the result of a built-in formula in the Google Apps Script, from the code send the desire inputs to the spreadsheet and retrieve the result of the built-in formula.
I have tried this for regular scripts. It does not work for user defined functions. I needed the =NORMSINV() function in a user defined function, and had no other option than to import code into my script...
As said, it's a conceptual solution, not a practical one. I am certain this is extremely expensive in terms of script efficiency.
Bear in mind the Google Apps Script is base on JavaScript 1.6, which has a lot of functionality in itself. You may want to check:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
This page on the Google Developers website has all the information you'd need to create functions.
In short, you need to go the Script Editor (Tools -> Script Editor) inside the spreadsheet, write the function and then access it from your spreadsheet cells.