Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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
Javascript 从电子表格模式html表单访问Google应用程序脚本中的数据_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 从电子表格模式html表单访问Google应用程序脚本中的数据

Javascript 从电子表格模式html表单访问Google应用程序脚本中的数据,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我有谷歌电子表格脚本,它将使用SpreadsheetApp.getUi()显示模态对话框。showModalDialog使用一个html表单,该表单在电子表格脚本项目中创建为文件 以下是我的Google脚本项目结构: --Code.gs | |- openFormModalDialog() |- fetchData() |- updateSheet() | --form.html 单击Code.gs模式中显示的my form.html中的按钮时,我将调用my Code.gs中的函数来

我有谷歌电子表格脚本,它将使用
SpreadsheetApp.getUi()显示模态对话框。showModalDialog
使用一个html表单,该表单在电子表格脚本项目中创建为文件

以下是我的Google脚本项目结构:

--Code.gs
 |
 |- openFormModalDialog()
 |- fetchData()
 |- updateSheet()
 |
--form.html
单击Code.gs模式中显示的my form.html中的按钮时,我将调用my Code.gs中的函数来处理用户在表单中输入的数据。我在表单中有多个输入字段

我想访问表单输入值以进行外部服务调用、获取和更新的工作表行

我无法理解如何访问应用程序脚本中表单中的数据

以下是我打开表格的方式:

function openFormModalDialog() {
  var ui = SpreadsheetApp.getUi();
  var htmlOutput = HtmlService
     .createHtmlOutputFromFile('form')
     .setWidth(400)
     .setHeight(300);
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'User Information');
}

有没有一种方法可以将我的应用程序脚本函数作为参数传递给html?我找不到任何与此相关的文件

我认为您应该使用google.script.run api

例如:


单击我运行测试()
现在,我已经添加了多个
提示符
以获取用户的输入,并在应用程序脚本中使用。我已经更新了我的答案,如果您需要解释,请告诉我您使用的方法的文档明确说明了如何与应用程序脚本通信: