根据 Google 电子表格数据在 Google 表单问卷中创建复选框
Create checkboxes in Google Form Questionnaire from Google Spreadsheet Data
我见过一百万个相似的东西,但实际上对此没有任何帮助。
我有一个 Google Sheet 大约有 900 条记录。我想创建一个可以导入该数据的 Google 表单,并在 Google 表单中为每个 GS 记录创建一个复选框。我知道 App Scripts 可以通过研究这个来做很多很酷的事情,但我还没有发现任何对完成这项工作有帮助的东西。
有没有人将 GS 数据导入 Google 表单来为 GS 记录创建复选框?
听起来你的问题分为两部分:
1。如何从价差中获取数据sheet?
使用Range class的.getValues()
方法获取传播sheet数据。了解更多关于价差结构的信息会有所帮助sheet,但假设您有一个名为“期权”的 sheet 并且您想要的数据在 A1:A10
范围内 sheet,你可以这样做:
// Get question data from the sheet
var sheet = SpreadsheetApp.getActive().getSheetByName('Options')
var choices = sheet.getRange("A1:A10").getValues()
// .getValues() returns a rectangular array, so we want the first (only) value in each row.
.map(function(row){return row[0]})
现在您在 choices
中有一个数据数组。
2。如何将此数据添加到表单的复选框项?
我假设您想 create a new form 回答这个复选框问题。如果您想在现有表格中插入问题,请使用 FormApp.openById()
或 FormApp.openByUrl()
而不是 FormApp.create()
// Create the form and add the question item
var form = FormApp.create("{Form Title}")
var item = form.addCheckboxItem()
.setTitle("{Question Title}")
.setChoiceValues(choices)
请参阅 .addCheckBoxItem()
and .setChoiceValues()
的文档
我见过一百万个相似的东西,但实际上对此没有任何帮助。
我有一个 Google Sheet 大约有 900 条记录。我想创建一个可以导入该数据的 Google 表单,并在 Google 表单中为每个 GS 记录创建一个复选框。我知道 App Scripts 可以通过研究这个来做很多很酷的事情,但我还没有发现任何对完成这项工作有帮助的东西。
有没有人将 GS 数据导入 Google 表单来为 GS 记录创建复选框?
听起来你的问题分为两部分:
1。如何从价差中获取数据sheet?
使用Range class的.getValues()
方法获取传播sheet数据。了解更多关于价差结构的信息会有所帮助sheet,但假设您有一个名为“期权”的 sheet 并且您想要的数据在 A1:A10
范围内 sheet,你可以这样做:
// Get question data from the sheet
var sheet = SpreadsheetApp.getActive().getSheetByName('Options')
var choices = sheet.getRange("A1:A10").getValues()
// .getValues() returns a rectangular array, so we want the first (only) value in each row.
.map(function(row){return row[0]})
现在您在 choices
中有一个数据数组。
2。如何将此数据添加到表单的复选框项?
我假设您想 create a new form 回答这个复选框问题。如果您想在现有表格中插入问题,请使用 FormApp.openById()
或 FormApp.openByUrl()
而不是 FormApp.create()
// Create the form and add the question item
var form = FormApp.create("{Form Title}")
var item = form.addCheckboxItem()
.setTitle("{Question Title}")
.setChoiceValues(choices)
请参阅 .addCheckBoxItem()
and .setChoiceValues()