我需要找到一种方法,让 Google 表单中的多项选择选项根据 Google 电子表格中不断变化的一组单元格进行更改。有什么想法吗?
最佳答案
这是可能的。在电子表格中编写您自己的脚本来更新您的表单。如果您不熟悉编写脚本,您可能会在 Google 脚本库中找到某人的脚本。让我们看看我的脚本示例。该脚本用于更新两个列表框。
function updateForm(){
// a way to get the items from the form
var form = FormApp.openById("<your form id>");
var agentList = form.getItemById(<your item id>).asListItem();
var hotelList = form.getItemById(<your item id>).asListItem();
var ss = SpreadsheetApp.getActive();
var agents = ss.getSheetByName("Agents");
var hotels = ss.getSheetByName("Hotels");
// get the values in the first column accept header row 1
var agentValues = agents.getRange(2, 1, agents.getMaxRows() - 1).getValues();
var hotelValues = hotels.getRange(2, 1, hotels.getMaxRows() - 1).getValues();
var agentNames = [];
var hotelNames = [];
// convert 2D to 1D array and ignore empty cells
for(var i = 0; i < agentValues.length; i++) {
if(agentValues[i][0] != "") {
agentNames[i] = agentValues[i][0];
}
}
for(var i = 0; i < hotelValues.length; i++) {
if(hotelValues[i][0] != "") {
hotelNames[i] = hotelValues[i][0];
}
}
// populate the list
agentList.setChoiceValues(agentNames);
hotelList.setChoiceValues(hotelNames);
}
您还可以将此功能链接到电子表格编辑/更改事件,以使列表自动更新。
关于google-apps-script - Google Spreadsheet Form,根据电子表格填充表单选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8084953/