【问题标题】:google.script.run is broken when used in a shared library [duplicate]google.script.run 在共享库中使用时被破坏[重复]
【发布时间】:2014-03-20 19:33:04
【问题描述】:

我有以下code.gs

function test() {
  Logger.log("Whoo hoo! test() called");
}

function showPopup() {
  var html = HtmlService.createTemplateFromFile('index').evaluate().setWidth(400).setHeight(300);
  SpreadsheetApp.getUi().showModalDialog(html, 'Click the button');  
}

连同这个 index.html

<div>
  <input type='button' onclick='google.script.run.test()' value='Test'>
</div>

这些工作正常:运行 showPopup() 后,我单击按钮,消息出现在日志中 example

当我使用“Resources->Libraries...”菜单项将此项目作为库添加到另一个电子表格时,问题就出现了。假设我给库命名为“Test”,然后在我运行Test.showPopup() 的新电子表格上,它会弹出弹出窗口。但是当我点击按钮时,它不会调用 test() 函数。

相反,电子表格上的控制台抱怨“未定义不是函数”。问题似乎是使用库管理器共享代码时 google.script.run.test() 不起作用。它想要 google.script.run.Test.test() 之类的东西,但我试过了,但它也不起作用:“无法读取未定义的属性 'test'”。

有什么方法可以在共享(库)脚本中使用 google.script.run 吗?

或者我可以通过其他方式在其他电子表格中重复使用我的代码,而无需将所有文件剪切并粘贴到每个文件中?

啊,好像是别人reported this as a bug。嘘。有什么解决方法吗?

【问题讨论】:

  • 你好,何塞!我的情况完全一样。如果您找到了解决方案,请提示如何使其工作? google-apps-script-issues 的回答对我没有帮助

标签: google-apps-script


【解决方案1】:

我也在想同样的事情。到目前为止,还没有看到真正的答案。 我的答案不是最好的,但我在脚本上管理了一个解决方法:

function test() {
  Test.test();
}

我很想知道这个问题的真正解决方案。

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多