美好的一天,
我有一个包含120多个问题的Google表单问卷,所有选项都相同而且在复选框上,有没有办法将复选框转换为下拉列表?这种方式使用标签更清晰,更容易选择。
我目前正在手动完成,但是还有很多其他问卷调查问卷。
非常感谢,祝你有个美好的一天!
答案 0 :(得分:1)
是。这很容易。你看过documentation了吗?您只需使用FormApp
并使用FormAp.getItems(FormApp.ItemType.LIST)
即可获取列表中的所有项目。然后,您需要做的就是迭代该列表并执行以下操作:
LIST
项目获取(所有项目均为ITEM
型)CHECKBOX
商品虽然我反对提供代码,并且会让你自己写代码,但它是如此微不足道,以至于我不妨把它给你:
编辑:我误解了这个问题,并认为目标是将下拉列表更改为复选框,而不是复选框下拉列表。编辑代码以反映相反的目标
要自己调整代码,您确实只需更改几行。 var itemList = form.getItems(FormApp.ItemType.LIST)
根据enum ItemType进行更改,并将oldItem
和newItem
更改为as
和add
各自的类型。
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
}
}