How to set correct answer text in google forms from spreadsheet using script

久未见 提交于 2021-01-29 10:23:45

问题


I want to make auto-grading short-answer quiz using google forms.

The data is in spreadsheet.

  • column A has questions.
  • column B has correct answers.
  • column C has explanations.

The code below makes quiz, but don't set correct answer in each question.

"item.createResponse(an);" seems not working.

How do I set correct answer?

let form = FormApp.openById(formID);
form.setIsQuiz(true);

// get data from sheet
let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('문제');
let range = ss.getDataRange();
let data = range.getValues()

data.forEach(function(el){

    // data
    let qu = el[0];                       //question
    let an = el[1].trim().toUpperCase();  //correct answer
    let ex = el[2];                       //explanation

    // create each question
    let item = form.addTextItem();
    item.setPoints(1);
    item.setTitle(qu);

    // create correct answer
    item.createResponse(an);

    // create explanation
    let exp = FormApp.createFeedback().setText(ex).build();
    if(ex != '') {
      item.setGeneralFeedback(exp);
    }
  })

回答1:


It's not possible to set correct answers for Text items using the Apps Script. It's only possible from the user interface.

It has been requested on Google's Issue Tracker. You can click on the star next to the issue number to receive updates and to give more priority to the request.



来源:https://stackoverflow.com/questions/61629776/how-to-set-correct-answer-text-in-google-forms-from-spreadsheet-using-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!