如何将 google 电子表格中的信息拉回 google 表单以更新信息?
我希望能够在表单中再次提取我已经通过 Google 表单提交的信息以更新信息。我知道我可以去编辑电子表格,但出于我的目的,通过表格更容易做到这一点。我一直无法找到允许我执行此操作的脚本。有没有人有什么建议?
如何将 google 电子表格中的信息拉回 google 表单以更新信息?
我希望能够在表单中再次提取我已经通过 Google 表单提交的信息以更新信息。我知道我可以去编辑电子表格,但出于我的目的,通过表格更容易做到这一点。我一直无法找到允许我执行此操作的脚本。有没有人有什么建议?
您可以在 Apps 脚本中使用 FormApp 来访问表单对象以进行更新。
下面是一个更新“从列表中选择”对象的示例。如果您想在每次提交后更新表单,您可以使用基于容器的触发器“On form submit”调用 updateList 函数。
function updateList(){
var form = FormApp.openById(formId);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// get the range of values to update in the form
var data = sheet.getRange(2,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();
var listItemsToAdd = [];
for(s in data){
if(logic to define if to add to the form){
listItemsToAdd.push(data[s][0]);
}
}
// get all the list items in the form
var list = form.getItems(FormApp.ItemType.LIST);
// grab the first list item in the array of the form's list items
var item = list[0].asListItem();
// set the options to the array just created
item.setChoiceValues(listItemsToAdd);
}