我正在努力将数据从Google表单提取到Google表格中,而我的问题是我仍在寻找如何从表单将特定数据获取到Google表格中, 我有一个Google表单,其中有一些信息,我想知道如何将答案分隔在不同的Google表格中
在Google应用脚本编辑器中可以输入任何脚本吗?
谢谢。
答案 0 :(得分:0)
var form = FormApp.openById('XXXXXXXXXXXXXXXXXXXXXXXXX');
ScriptApp.newTrigger('myFunction')
.forForm(form)
.onFormSubmit()
.create();
function myFunction() {
var array=[];
var formResponses = form.getResponses();
//i loops through all form submissions, e.g. if 3 users submitted a form - there will be three entries for formResponse
for (var i = 0; i < formResponses.length; i++)
{
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
// if you are only interested in the answer to question number "j"
var j=1;
var itemResponse = itemResponses[j-1];
array.push(itemResponse.getResponse());
}
Logger.log(array);
}
var form = FormApp.openById('XXXXXXXXXXXXXXXX');
var ss=SpreadsheetApp.getActiveSpreadsheet();
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
function readSheet() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getActiveSheet();
var responses=sheet.getDataRange();
//If you are interested in the response to question 3:
var k=3;
for(var i=0;i<sheet.getLastRow();i++)
{
Logger.log("The response to question "+responses.getValues()[0][k]+" submitted "+ responses.getValues()[i][0]+" is: "+responses.getValues()[i][k])
}
}