打开HTML Web应用程序时运行多个脚本

时间:2017-07-18 09:02:49

标签: google-apps-script

打开HTML网络应用程序时如何运行多个脚本......?

下面是我的示例脚本,当用户打开HTML Web应用程序时,第二个(函数getMail)脚本应该运行并捕获已定义表单中的电子邮件ID

function doGet() {
  return HtmlService
      .createTemplateFromFile('index')
   .evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
  return html;
}

  function getMail() {
  Logger.log(Session.getActiveUser().getEmail());
  var value = Logger.getLog();
  var ss = SpreadsheetApp.openById("1IRpIzJKdc50dz99hYHoUVUBuwwhZI4NGdEKbc2QWqS8").getActiveSheet();
  ss.getRange(ss.getLastRow()+1,1).setValue(value);
}

function getData() {
  return SpreadsheetApp
      .openById('1P0Z_njzrwjiPHrynDW37OTjwaPPFvntpiyBYSNBXt40')
      .getDataRange()
      .getValues();
}

1 个答案:

答案 0 :(得分:0)

您可以使用下一种语法从getMail模板调用Google Apps脚本功能index.html

<? getMail() ?>

详细文档:https://developers.google.com/apps-script/guides/html/templates#calling_apps_script_functions_from_a_template