问题
Is it possible to create a quiz form using GAS from a list of questions and answers on the spreadsheet? I'm making a word test for English learners, on which test-takers are asked to type an answer for each question. I've created a quiz with multiple questions or with radio buttons..., but I have been not able to import TEXT answers from spreadsheets to the TEXT-type quiz.
The script I have is below...
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var range = ss.getDataRange();
var data = range.getValues();
var numberRows = range.getNumRows();
var numberColumns = range.getNumColumns();
var firstRow = 1;
var form = FormApp.openById('');
for(var i=0;i<numberRows;i++){
var questionType = data[i][0];
if (questionType==''){
continue;
}
else if(questionType=='TEXT'){
form.addTextItem()
.setTitle(data[i][1])
.setHelpText(data[i][2])
.setRequired(true);
}
回答1:
I was ecstatic when Google finally let this happen with GAS. Check out this Google blog about creating a quiz using GAS. The scripting for the individual questions is shown below.
// Make a 10 point question and set feedback on it
var item = FormApp.getActiveForm().addCheckboxItem();
item.setTitle("What flavors are in neapolitan ice cream?");
item.setPoints(10);
// chocolate, vanilla, and strawberry are the correct answers
item.setChoices([
item.createChoice("chocolate", true),
item.createChoice("vanilla", true),
item.createChoice("rum raisin", false),
item.createChoice("strawberry", true),
item.createChoice("mint", false)
]);
回答2:
- Get a look on documentation sample
- Once you understand how does it work, start by adding addTextItem()
- Adapt it to your sheet/needs
Example:
- I have this list of questions on column A:
- And now I want to convert these questions into this form:
- Source code which you should adapt to your needs:
function convertToForm(){
const ss = SpreadsheetApp.getActive().getActiveSheet();
const questionList = ss.getRange("A1:A7").getValues();
const form = FormApp.create('New Form');
questionList.forEach( (question) => {
const item = form.addTextItem();
item.setTitle(question[0])
})
// press Ctrl+Enter to see form urls
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
}
Reference:
- Forms
- addTextItem()
来源:https://stackoverflow.com/questions/60646633/how-to-create-google-form-quiz-using-google-apps-script-or-gas