【发布时间】: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 的回答对我没有帮助