【发布时间】:2020-04-12 02:25:06
【问题描述】:
目前使用以下应用程序脚本功能将一列数据更新到我的谷歌表单的一个部分。但是,我想编写一个代码,我可以将多行数据更新到谷歌表单的多个部分。
示例:第 1 列更新到第 1 节,第 2 列更新到第 2 节等等。
function updateForm(){
// call your form and connect to the drop-down item
var form = FormApp.openById("Form Id");
var namesList = form.getItemById("Dropdown List ID").asListItem();
// identify the sheet where the data resides needed to populate the drop-down
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("Sheet Name");
// grab the values in the first column of the sheet - use 2 to skip header row
var namesValues = names.getRange(2, 10, names.getMaxRows() - 1).getValues();
var shopperNames = [];
// convert the array ignoring empty cells
for(var i = 0; i < namesValues.length; i++)
if(namesValues[i][0] != "")
shopperNames[i] = namesValues[i][0];
// populate the drop-down with the array data
namesList.setChoiceValues(shopperNames);
}
【问题讨论】:
标签: google-apps-script google-sheets google-forms