【发布时间】:2020-05-21 22:41:26
【问题描述】:
我在谷歌脚本中创建了一个脚本,以获取电子表格并成功填写多个谷歌文档。我正在尝试将此逻辑应用于填写 HTML 表单,基本上,我们需要用户生成的信息(在我们的 google 表格中)来填写网页上的 HTML 表单。
如何让以下函数不仅打开而且写入数据?
这就是我所在的位置(仅使用示例网页):
function testNew(){
var js = " \
<script> \
window.open('https://colorlib.com/etc/cf/ContactFrom_v1/index.html', '_blank', 'width=800, height=600'); \
google.script.host.close(); \
</script> \
";
var html = HtmlService.createHtmlOutput(js)
.setHeight(10)
.setWidth(100);
SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Spreadsheet
// DocumentApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Document
// SlidesApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Slides
}
这是我对谷歌文档所做的一个例子,试图在表单中复制:
function myFunction() {
var data = Sheets.Spreadsheets.Values.get('google sheet ID HERE', 'A2:R300');
// google doc template id, already got deal memo
var templateId = 'google doc ID HERE';
// loop through the values "i" is looping the rows, "#" is the column example: 0=a,1=b
for (var i = 0; i < data.values.length; i++) {
var date = data.values[i][0];
var email = data.values[i][1];
// grab the google doc template, create a copy, and generate the new id
var documentId = DriveApp.getFileById(templateId).makeCopy().getId();
// change the name of the new file
DriveApp.getFileById(documentId).setName(companyName+ '-' + projectName+ '-' + 'Insurance Report');
// get the document body as a variable
var body = DocumentApp.openById(documentId).getBody();
// replace values with google sheet data
body.replaceText('##Date##', date);
body.replaceText('##Email##', email);
【问题讨论】:
-
html 表单在哪里托管?
-
是公司网站吗?
-
是的,基本上是在尝试创建一个系统来为数百个客户填写表单,因为他们不会集成 CSV 上传器。
-
您为什么不想使用您当前的网站数据库。
-
这不是我的网站,如果可以的话完全可以。基本上,该表格来自另一家需要我们填写(并且不接受 CSV)的公司,我们的数据库中有所有答案,并正在尝试使用谷歌脚本或其他方法来获取这些 csv 并填写他们的在线表格,每次我们得到一个新客户。
标签: javascript html google-apps-script google-sheets web-crawler