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

B-S*_*art 1 html google-apps-script

这让我疯了.我为我的Google网络应用编写了一个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");

}
Run Code Online (Sandbox Code Playgroud)

我需要在单击按钮时调用该函数,我尝试了类似的东西(甚至没有google.script.run部分):

<button onclick="google.script.run(test())">Full</button>
Run Code Online (Sandbox Code Playgroud)

但我无法让我的按钮实际调用脚本.我读过你可以调用脚本通过只是把它们()函数来运行标记为好,但我想这能上点击,而不是负载运行.也许我只是不理解.gs和.html文件之间的联系.它们是单独的文件,但在同一个Google Web应用程序项目中.

Ala*_*lls 5

你的语法有点错误.你有:

<button onclick="google.script.run(test())">Full</button>
Run Code Online (Sandbox Code Playgroud)

应该:

<button onclick="google.script.run.test()">Full</button>
Run Code Online (Sandbox Code Playgroud)

你有一个括号,其中应该有一个点.

Google文档 - Google Script Run API