谷歌电子表格示例代码不起作用

google spreadsheet example code does not work

本文关键字:代码 不起作用 电子表格 谷歌      更新时间:2023-12-23

我已经多次尝试在谷歌电子表格上的这个链接上运行第一个示例代码:https://developers.google.com/apps-script/guides/html/best-practices

代码.gs:

function doGet(request) {
  return HtmlService.createTemplateFromFile('Page')
      .evaluate();
}
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

Page.html:

<?!= include('Stylesheet'); ?>
<h1>Welcome</h1>
<p>Please enjoy this helpful script.</p>
<?!= include('JavaScript'); ?>

样式表.html:

<style>
p {
  color: green;
}
</style>

JavaScript.html:

<script>
window.addEventListener('load', function() {
  alert('Page is loaded');
});
</script>

当我运行代码时,它会说"正在运行脚本",然后是"完成脚本",但我看不到结果。原因可能是什么?

如果您从代码编辑器运行代码,您将不会看到结果,您需要保存脚本的新版本,并将其发布为以用户身份运行的web应用程序。访问web应用程序时,您可以在此处看到说明。