从Google表单中提取复选框或多项选择选项 [英] Extract Checkbox or Multiple-choice Choices from a Google Form that Already Exists

查看:884
本文介绍了从Google表单中提取复选框或多项选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个尚未发布的Google表单。我想提取所有表单的项目,项目类型和项目选项(如适用)以用于邮件合并。我无法使用由Google创建的Response电子表格,因为表单的用户可能不会选择给定项目的所有可用选项。

I have created a Google Form that has not yet been published. I would like to extract all of the form's items, item types, and item choices (as applicable) for use in a mail merge. I can't use the Response spreadsheet, created by Google, because the form's users may not select all of the available choices for a given item.

我的脚本功能充分,除非试图将复选框(或多项选择题或网格问题)的选项写入电子表格。当使用getChoice方法时,我的电子表格会显示一组单元格= {Choice,Choice,Choice}。它反复显示了选择一词,而不是在我的表单上创建的实际选项。

My script functions adequately, except when trying to write the choices of a checkbox (or multiple-choice question or grid question) to the spreadsheet. When using the "getChoice" method, my spreadsheet shows an array of cells "={"Choice","Choice","Choice"}." It shows the word "Choice" over and over, instead of the actual choice that has been created on my form.

如何将实际选项写入电子表格,而不是数组中的选择一词?

How can I write the actual choices to my spreadsheet, instead of the word "Choice" in an array? I am a javascript noob, so my apologies for any inelegant coding!

function extractForm() {
  var existingform = FormApp.openByUrl('https://docs.google.com/a/forms/d/fc/viewform');
  var items = existingform.getItems();
  var itemcount = existingform.getItems().length
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  

  for (var i = 1; i <= itemcount; ++i) {
  if (items[i].getType() != 'PAGE_BREAK' && items[i].getType() != 'SECTION_HEADER') {
    sheet.getRange(i,1).setValue(i);
    sheet.getRange(i,2).setValue(items[i].getTitle());
    sheet.getRange(i,3).setValue(items[i].getType());
    };
  if (items[i].getType() == 'CHECKBOX') {
    var chkItem = items[i].asCheckboxItem();
    var choicecount = chkItem.getChoices().length
    for (var j = 1; j <= choicecount; ++j) {
      sheet.getRange(i,4,1,j).setValue(chkItem.getChoices());
    };
    };
  };
};


推荐答案

不应该简单地获取数组元素值对于(var j = 1; j< = choicecount; ++ j){
表单,

Shouldn't you simply get the array elements values like that ?

for (var j = 1; j <= choicecount; ++j) {
  sheet.getRange(i,4,1,j).setValue(chkItem.getChoices()[j].getValue());
};

这篇关于从Google表单中提取复选框或多项选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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