是否可以使用GAS从电子表格上的问题和答案列表中创建测验表单?我正在为英语学习者进行单词测试,要求考生为每个问题键入答案。我创建了一个包含多个问题或单选按钮的测验...,但是我无法将电子表格中的TEXT答案导入到TEXT类型的测验中。
我的脚本在下面...
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var range = ss.getDataRange();
var data = range.getValues();
var numberRows = range.getNumRows();
var numberColumns = range.getNumColumns();
var firstRow = 1;
var form = FormApp.openById('');
for(var i=0;i<numberRows;i++){
var questionType = data[i][0];
if (questionType==''){
continue;
}
else if(questionType=='TEXT'){
form.addTextItem()
.setTitle(data[i][1])
.setHelpText(data[i][2])
.setRequired(true);
}
当Google最终让GAS做到这一点时,我感到欣喜若狂。查看this Google blog有关使用GAS创建测验的信息。下面显示了各个问题的脚本。
// Make a 10 point question and set feedback on it
var item = FormApp.getActiveForm().addCheckboxItem();
item.setTitle("What flavors are in neapolitan ice cream?");
item.setPoints(10);
// chocolate, vanilla, and strawberry are the correct answers
item.setChoices([
item.createChoice("chocolate", true),
item.createChoice("vanilla", true),
item.createChoice("rum raisin", false),
item.createChoice("strawberry", true),
item.createChoice("mint", false)
]);
示例:
function runFatboyRun(){
const ss = SpreadsheetApp.getActive().getActiveSheet();
const questionList = ss.getRange("A1:A7").getValues();
const form = FormApp.create('New Form');
questionList.forEach( (question) => {
const item = form.addTextItem();
item.setTitle(question[0])
})
// press Ctrl+Enter to see form urls
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
}
参考: