[英]How to add a Worksheet function in Google Apps Script?
I want to use a built-in function in a Google Apps script. 我想在Google Apps脚本中使用内置函数。 Something similar to VBA
WorksheetFunction
How can I achieve that? 类似于VBA
WorksheetFunction
如何实现?
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); 从电子表格嵌入的Google Apps脚本中,链接到电子表格和两个范围:1)通过第一个链接将值输入到一个或多个输入单元格中; 2) through the second link retrieve the result of the formula.
2)通过第二个链接检索公式的结果。
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. 每当您在Google Apps脚本中需要内置公式的结果时,都会从代码中将所需的输入发送到电子表格,并检索内置公式的结果。
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...
我需要用户定义函数中的= NORMSINV()函数,除了将代码导入到脚本中之外,别无选择。
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. 请记住,Google Apps脚本基于JavaScript 1.6,而JavaScript 1.6本身具有很多功能。 You may want to check:
您可能要检查:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference 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. Google Developers网站上的此页面包含创建功能所需的所有信息。
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. 简而言之,您需要进入电子表格内的脚本编辑器(工具->脚本编辑器),编写函数,然后从电子表格单元格中访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.