【问题标题】:How to call library function as custom function from spreadsheet formula?如何从电子表格公式中调用库函数作为自定义函数?
【发布时间】:2018-04-02 18:09:42
【问题描述】:

这可能与How to call a library function from a spreadsheet drop-down menu generated by the same library 中的根本原因相同,但我仍然想把它扔掉,以防有新的东西或不知何故情况有所不同。

问题是我想将所有自定义函数保存在一个库中,然后将该库添加到任何给定的电子表格中,并能够从单元格公式中引用它们。 在图书馆:

/**
 * Returns the parameter
 * Eg: (16) to 16
 *
 * @param {object} theparameter the parameter.
 * @return {object} the same object.
 */
function ReturnParam(theparameter){
  return(theparameter);
}

在电子表格脚本中,添加库并给它一个标识符:myLib

在电子表格单元格公式中:

=myLib.ReturnParam(4)

=myLib.ReturnParam("hello")

单元格中的最终值为 4 或“你好”。

但它总是显示 Unknown function: 'myLib.ReturnParam' 错误。

我了解了在电子表格脚本中添加包装函数的解决方案,并且不喜欢其中的不便之处。

https://issuetracker.google.com/issues/36755072#comment20 中,有“解决方案”,但我无法掌握缺失的细节。 (有人可以详细说明吗?)

这个案子有希望吗?

是否有替代部署作为附加组件,即使不尝试对附加组件做任何花哨的事情?

我找不到 google-library 或 -libraries 标签。

【问题讨论】:

标签: google-apps-script google-sheets google-sheets-formula custom-function


【解决方案1】:

解决方案是在您的 Google Apps 脚本项目上创建一个调用库函数的函数

/**
 * Description of what your function does
 *  
 * @customfunction
 */
function ReturnParam(theParameter){
  return myLib.ReturnParam(theParameter);
}

然后您可以从电子表格中将其作为自定义函数调用

=ReturnParam(4)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    相关资源
    最近更新 更多