如何从电子表格公式中将库函数称为自定义函数? [英] How to call library function as custom function from spreadsheet formula?
问题描述
This might be the same root cause as in How to call a library function from a spreadsheet drop-down menu generated by the same library, but I still wanted to throw it out there in case there was something new or somehow the situation was different.
The thing is that I want to keep all my custom functions in a library, then add the library to any given spreadsheet, and be able to reference them from a cell formula. In the library:
/**
* Returns the parameter
* Eg: (16) to 16
*
* @param {object} theparameter the parameter.
* @return {object} the same object.
*/
function ReturnParam(theparameter){
return(theparameter);
}
在电子表格脚本中,添加库并为其指定一个标识符: myLib
在电子表格单元格公式中:
In the spreadsheet script, add the library and give it an identifier: myLib
In the spreadsheet cell formula:
=myLib.ReturnParam(4)
或
=myLib.ReturnParam("hello")
,单元格中的最终值为4或"hello".
但是,它始终显示 未知函数:'myLib.ReturnParam' 错误.
我了解了在电子表格脚本中添加包装器功能的解决方案,并且不喜欢这些不便之处.
在 https://issuetracker.google.com/issues/36755072#comment20,有一个解决方案",但是我无法掌握丢失的细节. (有人可以详细说明吗?)
对这种情况有希望吗?
即使不尝试对附加组件做任何花哨的工作,是否还有替代方案可以作为附加组件进行部署?
我找不到google-library或-libraries标记.
and the final value in the cell be 4 or 'hello'.
However it always shows an Unknown function: 'myLib.ReturnParam' error.
I read about the solutions to add wrapper functions in the spreadsheet script, and as well dislike the inconveniences.
In https://issuetracker.google.com/issues/36755072#comment20, there is "a solution", but I fail to grasp the missing details. (Can someone elaborate?)
Any hope for this case?
Is there an alternative deploying as an add-on, even if not trying to do anything fancy with the add-on?
I couldn't find a google-library or -libraries tag.
推荐答案
解决方案是在您的Google Apps脚本项目上创建一个调用库函数的函数
The solution is to create a function on you Google Apps Script project that calls the library function
/**
* Description of what your function does
*
* @customfunction
*/
function ReturnParam(theParameter){
return myLib.ReturnParam(theParameter);
}
然后您可以将其作为自定义功能从电子表格中调用
Then you could call it from your spreadsheet as a custom function
=ReturnParam(4)
这篇关于如何从电子表格公式中将库函数称为自定义函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!