如何使用Google Apps脚本或GAS创建Google表单测验? [英] How to create Google Form Quiz using Google Apps Script or GAS?

查看:296
本文介绍了如何使用Google Apps脚本或GAS创建Google表单测验?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 查看文档示例
  2. 一旦您了解了它的工作原理,请先添加 addTextItem( )
  3. 使其适应您的床单/需求
  1. Get a look on documentation sample
  2. Once you understand how does it work, start by adding addTextItem()
  3. Adapt it to your sheet/needs

示例:

  • 我在A列中列出了以下问题:

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

  • 您应该适应需要的源代码:
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());

}

参考:

  • Forms
  • addTextItem()

这篇关于如何使用Google Apps脚本或GAS创建Google表单测验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆