且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-25 13:30:15

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