如何使用Google Apps脚本或GAS创建Google表单测验?

问题描述 投票:0回答:2

是否可以使用GAS从电子表格上的问题和答案列表中创建测验表单?我正在为英语学习者进行单词测试,要求考生为每个问题键入答案。我创建了一个包含多个问题或单选按钮的测验...,但是我无法将电子表格中的TEXT答案导入到TEXT类型的测验中。

我的脚本在下面...

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);
  } 
google-apps-script google-form google-form-quiz
2个回答
1
投票

当Google最终让GAS做到这一点时,我感到欣喜若狂。查看this Google blog有关使用GAS创建测验的信息。下面显示了各个问题的脚本。

  // 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)
  ]);

0
投票
  1. 查看文档sample
  2. 一旦您了解了它是如何工作的,请先添加addTextItem()
  3. 使其适应您的工作表/需求

示例:

  • 我在A列中有此问题列表:

enter image description here

  • 现在我想将这些问题转换为这种形式:

enter image description here

  • 您应适应需要的源代码:
function runFatboyRun(){

  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());

}

参考:

© www.soinside.com 2019 - 2024. All rights reserved.