1 html javascript web-crawler google-sheets google-apps-script
我在谷歌脚本中创建了一个脚本,以获取电子表格并成功填写多个谷歌文档。我正在尝试将此逻辑应用于填写 HTML 表单,基本上,我们需要用户生成的信息(在我们的谷歌表中)来填写网页上的 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
}
Run Code Online (Sandbox Code Playgroud)
这是我对谷歌文档所做的一个例子,试图在表单中复制:
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);
Run Code Online (Sandbox Code Playgroud)
我编写了许多与许多第三方表单和网站交互的函数。不要让它愚弄你,一个表单就是一种人类可读的方式来“发布”到一个 url。更简单的方法是使用UrlFetchApp.fetch(url, options)
Google Apps 脚本中的函数。
我使用 Chrome,但其他浏览器也有此功能:
function senddatatoform() {
var url = 'http://theurlthattheformpoststohere.com'; // this is the 'request url' as shown in your browser (not always the url of the form).
var payload = {
datapoint1: datapoint1value,
datapoint2: datapoint2value,
... //continue with all required post data
}
var options = {
method: "POST",
payload: payload
}
var response = UrlFetchApp.fetch(url,options);
/*this is where what you need to do next might vary -- if you're looking for a 'success' page, you might write some code here to verify that the http response is correct based on your needs.
*/
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1489 次 |
最近记录: |