从谷歌表单创建多项选择测验

时间:2016-09-11 11:26:22

标签: google-form google-form-quiz

我正在尝试使用 GOOGLE FORMS 创建一个多选测验,从问题库中提问,结果存储在电子表格中。我已经知道如何创建测验并将数据存储在电子表格中,但我不知道如何使用问题库。任何人都可以帮我这个吗?

提前致谢。

2 个答案:

答案 0 :(得分:1)

最近,Google announced他们向Google Apps Script Forms服务添加了多种方法,以便能够以编程方式处理Google Forms测验。

由于这个原因,现在可以使用Google Apps Script从Google表格问题库创建测验。这实际上与从电子表格创建Google表单相同。

相关问题:

答案 1 :(得分:0)

我也对这个话题感兴趣,但我是一个完整的新手。 从现有的代码中汲取灵感,我得到了一个简单的脚本,令我惊讶的是,这个脚本似乎很有效。 我在下面对其进行了描述,但请注意,此帖更多是问题而不是答案。我希望得到更有经验的程序员的意见,因为我不确定我是否做得很好。

因此,在我的简单方案中,问题库看起来like this(请自行制作副本)。它应该是不言自明的,但

A栏:Id(目前尚未使用,但未来可能有用);

B栏:应该包含问题的文本(到目前为止只有Q1,Q2等占位符)

C栏:每个问题的多个选择的数量

D栏:正确的选择(以下栏目中的订单号)

E列及以下:多个选项的文本,与C列一样多(同样,目前只有占位符.A3Q2是问题2的答案3);

脚本如下。我在里面写了很多评论。 基本上,它通过名称" QBANK_1_form"创建一个表单,其中包含电子表格中列出的多项选择题的子集。 表单在变量destinationFolder指定的文件夹中创建。该脚本确保没有重复的文件(我在调试时得到了很多文件)。

同样,我非常喜欢来自更认真的程序员的一些见解。这是我的第一次尝试,可能非常笨拙。我甚至对此感到惊讶。

   function myFunction() {
  // Id of the spreadsheet containing the question bank
  var questionBankId = "1QCO-W2PxR9sLf2HtXreaEslyGTBdjswTgqxWDFycgKc"; 
  // name of the output form
  var formName = "QBANK_1_form"; 
  // Id of the destination folder (not root to keep things tidy)
  var destinationFolder = "ID_OF_YOUR_FOLDER_HERE"; // <-- change accordingly
  // variable containg the total number of questions in the question bank (read from spreadsheet)
  var question_num;
  // number of questions in the output form (question_req <= question_num)
  var question_req = 3; // chosen programmatically for the moment
  // other variables
  var r;
  var c;
  var ans;
  var item;
  var content;
  var choices =[];
  var nchoices;
  var correct;
  var iscorrect;

  // ======================================================================================
  // Delete possible files by the same name from target folder, to avoid duplicates
  // ======================================================================================
  // get target folder by ID
  var myFolder = DriveApp.getFolderById('0Bw56O_ircsfpSWM2N2FQbm1fUWM');
  // check if other files with the chosen name exist in the folder, 
  var thisFile = myFolder.getFilesByName(formName);
  // if this is the case, iterate over them
  while (thisFile.hasNext()) {
    // get next file
    var eachFile = thisFile.next();
    // get its Id
    var idToDLET = DriveApp.getFileById(eachFile.getId());
    // delete the file
    DriveApp.getFolderById(destinationFolder).removeFile(idToDLET);
  } 
  // --------------------------------------------------------------------------------------
  // ======================================================================================    
  // CREATE AND POPULATE THE FORM    
  // ======================================================================================
  // --------------------------------------------------------------------------------------
  // create the form
  var form = FormApp.create(formName);
  // ======================================================================================    
  // move the form to the desired folder (just for the sake of "housekeeping")    
  // ======================================================================================
  // get Id of the file
  var formFile = DriveApp.getFileById( form.getId() );  
  // add the to the desired folder
  DriveApp.getFolderById(destinationFolder).addFile( formFile );
  // delete the file from the roor folder
  DriveApp.getRootFolder().removeFile(formFile);
  // ======================================================================================    
  // start populating the form
  // ======================================================================================
  // open spreadsheet containing the question bank
  var ss = SpreadsheetApp.openById(questionBankId);
  // get number of questions in the question bank (number of rows-1);  
  var sheet = ss.getSheets()[0];
  question_num = sheet.getLastRow() - 1;
  // if question_req > question_num then set question_req=question_num, and the following is just a reshuffling of
  // the questions in the question bank
  if(question_req>question_num) {
     question_req=question_num;
  }
  // get random indexes for the question subset
  var index = questions(question_num,question_req);

  // Make sure the form is a quiz.
  form.setIsQuiz(true);


  // iteration of reading spreadsheet and writing form accordingly
  for(r = 0; r<question_req  ; r++){
     // create new multiple choice question
     item = form.addMultipleChoiceItem();      
     // set value if correct
     item.setPoints(10);
     // get question text from question bank and write it in form
     content = sheet.getRange(index[r]+1,2).getValue();
     item.setTitle(content);
     // get number of choices from question bank
     nchoices = sheet.getRange(index[r]+1,3).getValue();
     // get position of correct choice from question bank
     correct = sheet.getRange(index[r]+1,4).getValue();
     // create choice array
     for(c = 1; c<nchoices+1;c++){
        // determine whether the choice is correct
        iscorrect = (c==correct);
        // read choice from question bank
        content = sheet.getRange(index[r]+1,c+4).getValue();
        // add choice to choice array
        choices[c-1] = item.createChoice(content,iscorrect);           
     }
     // set choices
     item.setChoices(choices);

  }
}
// ------------------------------------------------------------------------------
// this function extracts question_req unique integers between 1 and question_num
// ------------------------------------------------------------------------------
function questions(question_num,question_req){
  var index = [];
  var ilist = [];
  var i;
  var n;


  // create and populate index list
  for (i = 0; i < question_num; i++) {
      ilist[i]=i+1;
  }
  // create indexes of random questions
  i = 0;
  while(i<question_req){
      n = Math.floor(Math.random() * (question_num-1));
      if(ilist[n]==n+1){
         index[i]=n+1;
         ilist[n]=-1;
         i++;
      }
  }
  return index;
}