如何发布到谷歌文档形式直接 [英] How to post to Google Docs Form directly
问题描述
我工作的一个项目,我需要从S preadsheet帖子我获得到谷歌表单中的数据,并获取数据。我不能使用谷歌Apps脚本,需要使用直接POST方法,我会做从GSM模块,该功能的方法。所有解决方案张贴previously考虑到谷歌形式提供了一个表格key.Like本一项所述的溶液的旧结构:
I'm working on a project where i need to post the data i acquire to a Google form and obtain the data from the spreadsheet. I cannot use google apps script and need a method using the direct POST method as i will be doing this function from a GSM module. All the solutions posted previously take into consideration the old structure of the Google form which provides a form key.Like the solution described in this one:
的http://www.open-electronics.org/how-send-data-from-arduino-to-google-docs-s$p$padsheet/
我目前的形式链接是这样的。
The link to my current form is this.
的https://docs.google.com/forms/d/14MkYG3fPNezzUC_nXUsWHlZ5JhplvjyWTAeob7f_W7g/viewform
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
难道一个谷歌的形式在这中间的要求?如果是足以能够将数据发布为preadsheet,这里有一个谷歌 - 应用程序 - 脚本的问题的一个方面:一个简单的Web服务将接受表单数据作为查询字符串,并写来您的S preadsheet。
Is it a requirement that a google form be in the middle of this? If it is enough to be able to post your data to a spreadsheet, here's a Google-Apps-Script for one side of the problem: a simple web service that will accept form data as a query string, and write that to your spreadsheet.
这例子假定一个非常简单的小号preadsheet,有三列,时间戳,COL1和COL2。编辑code,以适应您的情况。
This examples assumes a very simple spreadsheet, with three columns, "Timestamp", "col1" and "col2". Edit the code to suit your situation.
你可以看到在S preadsheet的此处,甚至进行测试后。
/**
* doGet() function to add data to a spreadsheet.
*
* Spreadsheet data is provided as a querystring, e.g. ?col1=1&col2='pizza'
*
* From: http://stackoverflow.com/a/18725479/1677912
*
* @param {event} e Event passed to doGet, with querystring
* @returns {String/html} Html to be served
*
* Test URLs (adjust ID as needed):
* https://script.google.com/macros/s/--DEV-SCRIPT-ID--/dev?col1=1&col2='pizza'
* https://script.google.com/macros/s/--PUB-SCRIPT-ID--/exec?col1=1&col2='pizza'
*/
function doGet(e) {
Logger.log( JSON.stringify(e) ); // view parameters
var result = 'Ok'; // assume success
if (e.parameter == undefined) {
result = 'No Parameters';
}
else {
var id = '--SHEET-ID---'; // Spreadsheet id for responses
var sheet = SpreadsheetApp.openById(id).getActiveSheet();
var newRow = sheet.getLastRow() + 1;
var rowData = [];
rowData[0] = new Date(); // Timestamp
for (var param in e.parameter) {
Logger.log('In for loop, param='+param);
var value = stripQuotes(e.parameter[param]);
//Logger.log(param + ':' + e.parameter[param]);
switch (param) {
case 'col1':
rowData[1] = value;
break;
case 'col2':
rowData[2] = value;
break;
default:
result = "unsupported parameter";
}
}
Logger.log(JSON.stringify(rowData));
// Write new row to spreadsheet
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
}
// Return result of operation
return ContentService.createTextOutput(result);
}
/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");
}
这篇关于如何发布到谷歌文档形式直接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!