如何从电子表格创建多选谷歌表格

时间:2017-03-01 11:54:23

标签: forms google-apps-script

我想从具有此类数据的现有电子表格中创建MCQ:

Question    Choice 1 (correct answer)   Choice 2    Choice 3    Choice 4
Question 1  a                            b                 c    d
Question 2  d                            a                 b    c
Question 3  b                            a                 b    c

感谢Chris的回答,但是这段代码:

function createForm(){
var form = FormApp.create('New Form');

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var range = sheet.getRange(2, 1, sheet.getLastRow());
var values = range.getValues();

for (var i = 0; i < values.length; i++) {
form.addMultipleChoiceItem()
   .setTitle(values[i][1])
   .setChoiceValues([values[i][2],values[i][3],values[i][4]]); //Make another loop here if your Answers counts are different
}
}

显示未填写的问题,如下所示: Form1 但是我想要创建的内容应该在最后看起来像这样: Form2

2 个答案:

答案 0 :(得分:1)

https://developers.google.com/apps-script/reference/forms/

 var form = FormApp.create('New Form');

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var range = sheet.getRange(2, 1, sheet.getLastRow());
 var values = range.getValues();

for (var i = 0; i < values.length; i++) {
    form.addMultipleChoiceItem()
       .setTitle(values[i][1])
       .setChoiceValues([values[i][2],values[i][3],values[i][4]]); //Make another loop here if your Answers counts are different
}

答案 1 :(得分:0)

这里我作为一个灵魂出现了:

    function createForm(){
var form = FormApp.create('New Form');

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var range = sheet.getRange(2, 1, sheet.getLastRow());
var values = range.getValues();

 var ansRange1 = sheet.getRange(2, 2, sheet.getLastRow());
 var ansValues1 = ansRange1.getValues();

var ansRange2 = sheet.getRange(2, 3, sheet.getLastRow());
var ansValues2 = ansRange2.getValues();

var ansRange3 = sheet.getRange(2, 4, sheet.getLastRow());
var ansValues3 = ansRange3.getValues();

var ansRange4 = sheet.getRange(2, 5, sheet.getLastRow());
var ansValues4 = ansRange4.getValues();

for (var i = 0; i < (values.length)-1; i++) {
   form.addMultipleChoiceItem()
   .setTitle(values[i])
   .setChoiceValues([ansValues1[i],ansValues2[i],ansValues3[i],  ansValues4[i] ]); //Make another loop here if your Answers counts are different
}
}

但是我仍然在努力做出正确的答案,并给出正确的答案:无需从表格中手动执行这两个步骤。 所以,如果有人能帮我解决这个问题,那我非常欢迎!