如何将信息从谷歌电子表格拉回谷歌表单以更新信息?
我希望能够在表单中再次提取我已经通过 Google 表单提交的信息以更新信息。 我知道我可以去编辑电子表格,但就我的目的而言,通过表单更容易完成。 我一直无法找到允许我执行此操作的脚本。 有人有什么建议吗?
您可以使用应用程序脚本中的 FormApp 访问要更新的表单对象。
下面是更新"从列表中选择"对象的示例。 如果要在每次提交后更新表单,可以使用基于容器的触发器"表单提交时"调用 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);
}