【问题标题】:Google sheets: Class google.script.run not working谷歌表:类 google.script.run 不起作用
【发布时间】:2019-11-12 15:09:54
【问题描述】:

我的问题很简单。我在网上搜索的所有可能的解决方案都没有解决我的问题。

Google 的类 google.script.run (https://developers.google.com/apps-script/guides/html/reference/run#withSuccessHandler) 的开发者网站展示了方法 myFunction(...)(任何服务器端函数)。

我已经复制了他们的确切代码和html代码,并推断出函数doSomething()没有执行。没有任何记录。

我打算用它来执行一个 HTML 文件,这样我就可以播放一个声音文件。到目前为止,我可以通过从侧面弹出一个侧边栏来做到这一点,如该线程中所述:Google Script: Play Sound when a specific cell change the Value

但是,Google 提供的这段代码不起作用。为什么?

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');
}

function doSomething() {
  Logger.log('I was called!');
}

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      google.script.run.doSomething();
    </script>
  </head>
  <body>
  </body>
</html>

【问题讨论】:

    标签: html google-apps-script google-sheets editor execute


    【解决方案1】:

    通过使用 google.script.run,您正在调用服务器端 Apps 脚本函数。 https://developers.google.com/apps-script/guides/html/reference/run 请仔细检查您是否按照以下步骤正确操作:

    1. 请确保将代码的 html 部分放在单独的 HTML 文件中(通过 File->New->HTML 文件创建),其名称与您在 HtmlService.createHtmlOutputFromFile() 中调用的名称相对应- 在你的情况下 Index.html
    2. 选择“doGet”作为要运行的函数。
    3. 将脚本部署为 Web 应用程序 - 这是使用 Apps Script HTML 服务的要求。请在此处找到说明:https://developers.google.com/apps-script/guides/web
    4. 确保每次在代码中实施更改后,将脚本部署为新的项目版本。这是更新更改所必需的。
    5. 打开您在更新版本后获得的当前 Web 应用 URL,以打开您的 html 输出。
    6. 在您的情况下,只会打开一个空的 HTML 文件,以测试功能 - 在您的 HTML 正文中插入一些文本,以测试正确的功能。后者可以通过运行代码后查看日志来确认。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 2013-07-19
      • 2015-09-28
      相关资源
      最近更新 更多