Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用HTMLService从gs文件调用函数?_Html_Google Apps Script - Fatal编程技术网

如何使用HTMLService从gs文件调用函数?

如何使用HTMLService从gs文件调用函数?,html,google-apps-script,Html,Google Apps Script,这让我快发疯了。我已经为我的Google web应用程序编写了一个html页面,它的函数写在一个.gs文件中。我所要做的就是从.html文件调用.gs文件中的函数。然而,我尝试过的每一种方法似乎都不起作用。我知道我的函数可以工作,因为当我只运行它们时它们就工作了。我不知道如何将.gs文件连接到.html文件 我的.gs文件如下所示: function doGet() { return HtmlService.createHtmlOutputFromFile('index'); } fun

这让我快发疯了。我已经为我的Google web应用程序编写了一个html页面,它的函数写在一个.gs文件中。我所要做的就是从.html文件调用.gs文件中的函数。然而,我尝试过的每一种方法似乎都不起作用。我知道我的函数可以工作,因为当我只运行它们时它们就工作了。我不知道如何将.gs文件连接到.html文件

我的.gs文件如下所示:

function doGet() {

  return HtmlService.createHtmlOutputFromFile('index');
}

function test()
{
  //getFormattedSpreadsheet("1xPDJJfCqWb2igug3NCFmJJ5nO49U6CK8mLwtaD727AY", "17qcsYh8M-cOwTg9K7sqqnKm0pGgEo6r7x1PguRf9Jk8", "Select School");
  archiveSheet("1wTNing5LAOYHbscQ_DTktIxvWcyc6gw6ZNTvAJDtkTo", "1ugNP0Pp97tnRKHLHa50j-QKx-4ynCfg3zHxtJTayiVk");

}
我需要在单击按钮时调用该函数,我尝试了以下操作(甚至没有google.script.run部分):

Full

但我无法让我的按钮实际调用脚本。我已经读过,您也可以通过将脚本放在function()标记中来调用脚本运行,但我需要在单击时而不是加载时运行脚本。也许我只是不理解.gs和.html文件之间的链接。它们是独立的文件,但在同一个Google web app项目中

您的语法有点错误。你有:

<button onclick="google.script.run(test())">Full</button>
Full
应该是:

<button onclick="google.script.run.test()">Full</button>
Full
你有一个括号,里面应该有一个点


您的语法有点错误。你有:

<button onclick="google.script.run(test())">Full</button>
Full
应该是:

<button onclick="google.script.run.test()">Full</button>
Full
你有一个括号,里面应该有一个点


经过几个小时的搜索,我完全错过了这一点,这让我很沮丧。我非常感谢你看到了它。刚刚测试过这个,它就像一个符咒!非常感谢!经过几个小时的搜索,我完全错过了这一点,这让我很沮丧。我非常感谢你看到了它。刚刚测试过这个,它就像一个符咒!非常感谢!