【问题标题】:Google sheets doesn't display the function on my scriptGoogle 工作表未在我的脚本上显示该功能
【发布时间】:2018-11-02 22:52:54
【问题描述】:

我对使用 Google 脚本非常陌生。我遇到了这个非常基本的问题,但我似乎找不到解释。 我在 Google 表格上编写了一个函数(从我想尝试代码的同一张表格中打开脚本编辑器)。事实证明,当我想使用我的功能时,Google 表格找不到它。这意味着,当我键入“=”加上函数名称时,我找不到它。我的代码如下:

function distance(origin,destination) {

    var mapObj = Maps.newDirectionFinder()

    mapObj.setMode(Maps.DirectionFinder.Mode.DRIVING)

    //Set the Orgin
    mapObj.setOrigin(origin)

    //Set the Destination
    mapObj.setDestination(destination)

    //Retrieve the Distance
    var directions = mapObj.getDirections();
    var meters = directions["routes"][0]["legs"][0]["distance"]["value"];
}

我将不胜感激!

【问题讨论】:

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


【解决方案1】:

我复制了你的函数,它似乎丢失了好吗!我找不到参考,但我认为“距离”在某种程度上是保留的。如果您将函数的名称更改为 getDistance(),它可以正常工作。

/**
 * Calculate the distance between origin and destination
 *
 * @param {Sheet3!B32}  reference  Cell or range to monitor.
 * @returns                        The distance.
 * @customfunction
 */
function getDistance(origin,destination) {
...
}

如果您像我一样在函数前添加jsDoc 评论,智能感知将起作用 - 即当您在公式栏中键入“=”时,您的评论内容将显示:

【讨论】:

    【解决方案2】:

    尝试使用:

    * @customfunction

    在函数之前的cmets中

    【讨论】:

      【解决方案3】:

      不确定您所说的“工作表找不到它”是什么意思。以下是一些可能会有所帮助的提示:

      1. 您可以使用以下代码轻松地将自定义菜单添加到任何文档:

        函数 onOpen() { var ui = SpreadsheetApp.getUi(); var menu = ui.createMenu("我的脚本菜单"); menu.addItem("菜单项 1", "function1").addToUi(); menu.addItem("菜单项 2", "function2").addToUi(); ...等等。 }

      当您打开文档时,将出现自定义菜单(等待几秒钟),您可以从“我的脚本菜单”中选择“function1”。

      1. 当您的 Google Apps 脚本项目打开时,“调试”菜单中没有选择任何函数。如果您正在使用调试器,请确保您选择了要运行的函数:

      单击向下箭头,然后选择要运行的函数。

      【讨论】:

        猜你喜欢
        • 2021-11-24
        • 1970-01-01
        • 1970-01-01
        • 2016-12-07
        • 1970-01-01
        • 2018-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多