【问题标题】:Why can't i log the output into logger of google sheets?为什么我不能将输出记录到谷歌表格的记录器中?
【发布时间】:2020-10-18 07:01:59
【问题描述】:

我试图将一些自定义脚本添加到 Google 表格中。但是,即使按照 GoogleCodeLabs 指南中给出的相同步骤进行操作,也会遇到很多问题。

这是我的代码 main.gs 文件

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

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

index.html 文件

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

appsscript.json 文件

{
  "timeZone": "Asia/Kolkata",
  "dependencies": {
  },
  "webapp": {
    "access": "MYSELF",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": ["https://www.googleapis.com/auth/spreadsheets.readonly",
                  "https://www.googleapis.com/auth/userinfo.email",
                  "https://www.googleapis.com/auth/spreadsheets",
                  "https://www.googleapis.com/auth/script.container.ui"],
  "runtimeVersion": "V8"
}

我也在部署它并进行每一个小的更改,但即使按照指南中提到的方式进行操作,我也无法记录输出。 我错过了什么?

【问题讨论】:

标签: google-apps-script google-sheets


【解决方案1】:

试试这个:

function myfun() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const html='<!DOCTYPE html><html><head><base target="_top"><script>google.script.run.withSuccessHandler(function(){document.getElementById("msg").innerHTML="I did something Useful";}).doSomething();</script></head><body><div id="msg"></div></body></html>';
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Dialog");
}

function doSomething() {
  console.log('something');
  return;
}

【讨论】:

    【解决方案2】:

    我最近在新的谷歌应用脚​​本编辑器上遇到了同样的事情。

    除非您从编辑器本身执行该功能,否则 Logger.log 不会在编辑器的“执行日志”上显示任何内容。

    但是,

    如果使用 google.script.run(客户端)执行具有 Logger.log 的函数,您将在“Executions”中看到使用 Logger.log 记录的任何内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 2022-11-27
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多