将复选框转换为Googleform上的下拉列表

时间:2016-12-15 08:23:48

标签: google-apps-script google-form

美好的一天,

我有一个包含120多个问题的Google表单问卷,所有选项都相同而且在复选框上,有没有办法将复选框转换为下拉列表?这种方式使用标签更清晰,更容易选择。

我目前正在手动完成,但是还有很多其他问卷调查问卷。

非常感谢,祝你有个美好的一天!

1 个答案:

答案 0 :(得分:1)

是。这很容易。你看过documentation了吗?您只需使用FormApp并使用FormAp.getItems(FormApp.ItemType.LIST)即可获取列表中的所有项目。然后,您需要做的就是迭代该列表并执行以下操作:

  1. 将当前项目作为LIST项目获取(所有项目均为ITEM 型)
  2. 创建新的CHECKBOX商品
  3. 将标题从旧项目复制到新项目
  4. 将帮助文本从旧项目复制到新项目
  5. 从旧项目复制到新项目
  6. 将选项从旧项目复制到新项目
  7. 获取新旧商品的索引
  8. 将新项目移至旧项目索引
  9. 删除旧项目
  10. 虽然我反对提供代码,并且会让你自己写代码,但它是如此微不足道,以至于我不妨把它给你:

    编辑:我误解了这个问题,并认为目标是将下拉列表更改为复选框,而不是复选框下拉列表。编辑代码以反映相反的目标

    要自己调整代码,您确实只需更改几行。 var itemList = form.getItems(FormApp.ItemType.LIST)根据enum ItemType进行更改,并将oldItemnewItem更改为asadd各自的类型。

    function myFunction() {
      var form = FormApp.getActiveForm()  
      var itemList = form.getItems(FormApp.ItemType.CHECKBOX)
      var oldItem, newItem, oldIndex, i
    
      for (i = 0; i < itemList.length; i++) {
        oldItem = itemList[i].asCheckboxItem()                      //get the item as a checkbox item to gain access to the choices
        newItem = form.addListItem()                                //create a new list item (you can use any other type)        
        newItem.setTitle(oldItem.getTitle())                        //copy the title
        newItem.setHelpText(oldItem.getHelpText())                  //copy the help text
        newItem.setRequired(oldItem.isRequired())                   //copy if it is required
        newItem.setChoices(oldItem.getChoices())                    //copy the choices
        oldIndex = oldItem.getIndex()                               //get where the current item is    
        form.moveItem(form.getItemById(newItem.getId()), oldIndex)  //move the new item to the old items position
    
    //    -----Another optional way to move the item----
    //    var newIndex = newItem.getIndex()
    //    form.moveItem(form.getItemById(newIndex, oldIndex)
    //    -----------------------------------------------    
    
        form.deleteItem(itemList[i])                                //delete the old item
      }
    
    }