Created
October 1, 2023 01:46
-
-
Save ochilab/c6776fcd7e1fb3eb11019866d06bd2fc to your computer and use it in GitHub Desktop.
GoogleシートのデータからGoogleフォーム(選択肢問題)を生成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createQuizForm() { | |
var row=10; //問題数 | |
var col=7; //シートの列数 | |
var form = FormApp.create('クイズフォーム(自動生成)'); // フォームのタイトルを設定 | |
form.setIsQuiz(true); | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
//シートのデータを全部取得 | |
var data = sheet.getDataRange().getValues(); | |
for (var i = 1; i <= 10; i++) { // 先頭のヘッダー行をスキップ | |
var questionTitle = data[i][0]; //1列目に問題文 | |
var correctAnswer = data[i][1]; //正解情報(正解選択肢ラベル) | |
var point = data[i][2]; // 得点 | |
var choices = data[i].slice(3, col); // 選択肢は2列目から4列目まで | |
var item = form.addMultipleChoiceItem(); | |
item.setTitle(questionTitle); | |
var choiceArray = []; | |
for(var j=0;j<choices.length;j++){ | |
//item.setChoiceValues(choices) | |
var cTitle=choices[j]; | |
if(choices[j]==correctAnswer){ //正解情報と選択肢ラベルの文字列一致で正解箇所設定 | |
choiceArray.push(item.createChoice(choices[j],true)); | |
} | |
else{ | |
choiceArray.push(item.createChoice(choices[j],false)); | |
} | |
} | |
item.setChoices(choiceArray); | |
item.setPoints(point); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment