And*_*ard 20 google-apps-script google-forms
我需要找到一种方法,让Google表单中的多项选项更改基于Google电子表格中不断变化的一组单元格.有任何想法吗?
小智 27
这是可能的.在电子表格中编写您的自己的脚本以更新您的表单.如果您不熟悉编写脚本,您可能会在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);
}
Run Code Online (Sandbox Code Playgroud)
您还可以将此功能链接到电子表格编辑/更改事件,以使列表自动更新.
您请求的功能当前不存在。将 Google 表单链接到电子表格的功能请求将是保持两者同步的最佳选择。
始终可以选择使用网址参数创建表单,如下所述: https: //docs.google.com/support/bin/answer.py ?hl=en&answer=160000
| 归档时间: |
|
| 查看次数: |
23930 次 |
| 最近记录: |