【发布时间】:2015-05-22 04:07:22
【问题描述】:
我正在尝试设置一个 Google 表单,该表单将创建一个“从列表中选择”问题,每个选项都是从特定列中的行中提取的。
我已经尝试过this code,但它根本不适合我。
我到目前为止的代码如下。我能够使用特定列中仅一行的数据(在本例中为该列的最后一行)创建所需的表单问题。
如果有人可以帮助我指出正确的方向,如何将每个选定的行分配给一个问题选项。 此外,如果这些是每次更新电子表格时动态更新问题选项的某种方式。
var idColumn = 1; // ID of the selected column
//gets document ID from spreadsheet
//(not 100% sure the role of all of these lines, have worked it out from other examples of code online)
function spreadSheetGetter() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
var docId = sheet.getRange(lr,idColumn,1,1).getValue(); //gets the data from the last row in selected column
fillFormData(docId);
}
//fills for with document ID
function fillFormData(docId) {
var form = FormApp.openById('MY FORMS ID');
var item = form.addListItem();
item.setTitle('Select Existing Customer') //creates the choose from list question
.setChoices([
item.createChoice(docId), //data from row 1
item.createChoice(docId) //data from row 2 etc...
])
}
【问题讨论】:
标签: google-apps-script google-sheets google-forms