我有Google电子表格脚本,该脚本将使用html表单使用SpreadsheetApp.getUi().showModalDialog
显示模式对话框,该表单在SpreadSheet脚本项目中创建为文件。
这就是我的Google Script项目结构:
--Code.gs
|
|- openFormModalDialog()
|- fetchData()
|- updateSheet()
|
--form.html
当我在我的form.html中单击按钮时,在Code.gs中显示模式,我想在我的Code.gs中调用一个函数来处理用户在表单中输入的数据。我在表单中有多个输入字段。
我想访问表单输入值以进行外部服务调用以及获取和更新表单行。
我无法弄清楚如何访问App Script中提交的表单中的数据。
这就是我打开表单的方式:
function openFormModalDialog() {
var ui = SpreadsheetApp.getUi();
var htmlOutput = HtmlService
.createHtmlOutputFromFile('form')
.setWidth(400)
.setHeight(300);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'User Information');
}
有没有办法可以将我的App-Script函数作为参数传递给html?我无法找到与此相关的任何相关文件。
答案 0 :(得分:1)
我认为你应该使用google.script.run api
示例:
<button onClick = "google.script.run.test();">Click me to run test()</button>
&#13;
这将运行您的test()
检查出来:https://developers.google.com/apps-script/guides/html/reference/run#myFunction(...)
我们传递参数可以像google.script.run.test("value1");
我们可以运行另一个功能(这里的网页/对话框中的javascript功能)此功能完成执行后,就像这样google.script.run.withSuccessHandler(nextFunctionName).test("value1");
我们还可以运行另一个功能(此处网页/对话框中的javascript功能)如果此功能执行失败,就像这样google.script.run.withFailureHandler(nextFunctionName).test("value1");