如何构建一个扩展,以保存HTML表单的值到电子表格使用应用程序脚本
How to build an extension to save values of HTML form to spreadsheet using app script
我试图建立一个扩展,以保存HTML表单的值使用谷歌应用程序脚本的电子表格。
我能够保存当我发布作为一个web应用程序通过应用程序脚本。
但是当我尝试从一个不工作的扩展相同。
当我们提交表单时,如何调用应用程序脚本URL以从扩展发布值到电子表格?
HTML:<form name="input">
<!-- fieldset draws a border around all the input elements -->
<fieldset>
<!-- There are form attributes, like type, name, id -->
<input type="text" value="Manufacturer"
class="ss-q-short" id="id_Maker" dir="auto" aria-required="true"
title=""> <br>
<br>
<br> <input type="button" value="Save Input"
onclick="WriteInput()"> <input type="reset" value="Reset">
</fieldset>
</form>
JS文件:
<script>
function WriteInput() {
alert("hello");
var d=new Date();
var daMonth = d.getMonth() + 1;
var ToInputStrng = (daMonth + "/" + d.getDate() + "/" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
alert(ToInputStrng);
var strngTwo = document.getElementById('id_Maker').value;
alert(strngTwo);
google.script.run.withFailureHandler(onFailure)
.withSuccessHandler(onSuccess)
.AddToSheet(ToInputStrng, strngTwo);
}
</script>
应用程序脚本:
function doGet(){
return HtmlService.createHtmlOutputFromFile('OfferedInput')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
function AddToSheet(InputData, InputTwo){
var sheet = SpreadsheetApp.openById("Put the spreadsheet ID here");
return sheet.appendRow([InputData, InputTwo]);
}
将"scriptlet"放入"OfferedInput" HTML文件中。"scriptlet"为<?!= include("JS"); ?>
。确保在HTML中使用<!DOCTYPE html><html>
和<body>
标签:
<!DOCTYPE html>
<html>
<head>
<?!= include("JS"); ?>
</head>
<body>
<form name="input">
<!-- fieldset draws a border around all the input elements -->
<fieldset>
<!-- There are form attributes, like type, name, id -->
<input type="text" value="Manufacturer"
class="ss-q-short" id="id_Maker" dir="auto" aria-required="true"
title="">
<br>
<br>
<br>
<input type="button" value="Save Input" onclick="WriteInput()">
<input type="reset" value="Reset">
</fieldset>
</form>
</body>
</html>
脚本使HTML文件成为"模板"。现在必须在doGet()
中使用createTemplateFromFile()
方法。你需要一个include()
函数。
function doGet() {
var template = HtmlService.createTemplateFromFile('OfferedInput');
// Build and return HTML in IFRAME sandbox mode.
return template.evaluate()
.setTitle('Web App Window Title')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
};
function include(filename) {
//Logger.log('filename: ' + filename)
return HtmlService.createHtmlOutputFromFile(filename).getContent();
};
将沙箱模式设置为IFRAME, NATIVE被认为已弃用。
相关文章:
- 窗口提醒或类似内容中的电子邮件表单
- 有没有一种方法可以使用Javascript检索谷歌表单ITSELF(而不是电子表格)的数据
- 限制每秒/分钟联系表单电子邮件
- HTML 表单不会使用 doPost 提交到电子表格
- Google Apps 脚本 - 表单不会自动邮寄电子表格响应
- 在复制到电子表格时将逻辑构建到 Google Apps 脚本表单中
- 谷歌电子表格网站表单jQuery脚本阻止发送
- 使用 JSON 将表单电子邮件发送到 REST 服务
- 使用 JavaScript 代码制作 HTML 表单和表格
- 此联系表单电子邮件脚本是否安全
- 表单电子邮件验证工作不正常
- 使用javascript在单个页面上验证多个表单电子邮件
- 如何在rails 4中创建一个联系人表单电子邮件,当网页在客户端
- 如何构建一个扩展,以保存HTML表单的值到电子表格使用应用程序脚本
- 谷歌表单从电子表格和电子邮件拉数据给用户
- 需要复制谷歌电子表格(自定义公式)和链接的谷歌表单
- Facebook注册表单电子邮件验证模式
- 使用电子表格向HTML表单提供信息
- Google Apps脚本-使用侧边栏表单向电子表格添加一行
- 联系表单电子邮件集成Javascript HTML