【发布时间】:2016-09-11 11:26:21
【问题描述】:
我正在尝试创建一个多项选择测验,它使用 GOOGLE FORMS 从问题库中提取问题,并将结果存储在电子表格中。我已经知道如何创建测验并将数据存储在电子表格中,但我不知道如何使用题库。谁能帮我解决这个问题?
提前致谢。
【问题讨论】:
-
“题库”是什么意思?电子表格?
标签: google-forms google-form-quiz
我正在尝试创建一个多项选择测验,它使用 GOOGLE FORMS 从问题库中提取问题,并将结果存储在电子表格中。我已经知道如何创建测验并将数据存储在电子表格中,但我不知道如何使用题库。谁能帮我解决这个问题?
提前致谢。
【问题讨论】:
标签: google-forms google-form-quiz
最近 Google announced 向 Google Apps Script Forms 服务添加了几种方法,使其能够以编程方式处理 Google Forms 测验。
多亏了这一点,现在可以使用Google Apps Script 从 Google 表格题库创建测验。这实际上与从电子表格创建 Google 表单相同。
相关问题:
【讨论】:
我也对这个话题很感兴趣,但我是个新手。 从现有的代码中汲取灵感,我编写了一个简单的脚本,令我惊讶的是,它似乎可以工作。 我将在下面对其进行描述,但请记住,这篇文章更多的是问题,而不是答案。我想听听更有经验的程序员的意见,因为我不确定我做的一切是否正常。
所以在我的简单方案中,问题库看起来是like this(请自己制作副本)。它应该是不言自明的,但是
A 列:ID(目前未使用,但将来可能有用);
B 列:应该包含问题的文本(目前只有 Q1、Q2 等占位符)
C 列:每个问题的多项选择数
D列:正确的选择(其序号在以下列)
E列及以下:多项选择的文本,与C列一样多(同样,暂时只有占位符。A3Q2是问题2的答案3);
脚本如下。我在里面放了很多cmets。 基本上,它会创建一个名为“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;
}
【讨论】: