You are on page 1of 1

// Open a form by ID.

var form = FormApp.openById('id');


// Open a sheet by ID.
var sheet = SpreadsheetApp.openById('id').getSheets()[0];

// variables for putting the questions and answers in the right position
var question_position = 0;
var answers_position = 0;

// main function to run


function getFormValues() {
form.getItems().forEach(callback);
}

// Iterate over all questions


function callback(el){

// check if the question is multiple choice


if (el.getType() == FormApp.ItemType.MULTIPLE_CHOICE) {
// change the type from Item to MultipleChoiceItem
var question = el.asMultipleChoiceItem();
var choices = question.getChoices();
// set the title of the question in the cell
// sheet.getRange(answers_position+1, 1).setValue(question.getTitle());
answers_position++;
var i = 0;
var ss = "";
// set the answers in the right cells
for (i; i < choices.length; i++){
//sheet.getRange(answers_position + 1, 1).setValue(choices[i].getValue());
ss = ss + choices[i].getValue() + "\n";
answers_position++;
}

sheet.getRange(answers_position+1, 1).setValue(question.getTitle() + "\n"+ss);

question_position += i;
answers_position++;
}
question_position++;

You might also like