通用表单项,包含所有项共有的属性,例如标题和帮助文本。
可以通过 Form
访问或创建项。
如需对特定于类型的属性执行操作,请使用 getType()
检查相应项的 ItemType
,然后使用 asCheckboxItem()
等方法将项转换为适当的类。
// Create a new form and add a text item. var form = FormApp.create('Form Name'); form.addTextItem(); // Access the text item as a generic item. var items = form.getItems(); var item = items[0]; // Cast the generic item to the text-item class. if (item.getType() == 'TEXT') { var textItem = item.asTextItem(); textItem.setRequired(false); }
实现类
名称 | 简介 |
---|
方法
详细文档
asCheckboxGridItem()
将该项作为复选框网格项返回。如果 ItemType
还不是 CHECKBOX_GRID
,则会抛出脚本异常。
弃踢回攻
CheckboxGridItem
- 复选框网格项
抛出
Error
- 如果内容不是复选框网格项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asCheckboxItem()
将项目作为复选框项返回。如果 ItemType
还不是 CHECKBOX
,则会抛出脚本异常。
弃踢回攻
CheckboxItem
- 复选框项
抛出
Error
- 如果该项不是复选框项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asDateItem()
asDateTimeItem()
将该项作为日期时间项返回。如果 ItemType
还不是 DATETIME
,则会抛出脚本异常。
弃踢回攻
DateTimeItem
- 日期时间项
抛出
Error
- 如果项不是日期时间项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asDurationItem()
将内容作为时长项返回。如果 ItemType
还不是 DURATION
,则会抛出脚本异常。
弃踢回攻
DurationItem
- 时长项
抛出
Error
- 如果项不是时长项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asGridItem()
asListItem()
asMultipleChoiceItem()
将该项作为单选题返回。如果 ItemType
还不是 MULTIPLE_CHOICE
,则会抛出脚本异常。
弃踢回攻
MultipleChoiceItem
- 单选题
抛出
Error
- 内容不是单选题时
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asPageBreakItem()
将该项作为分页符项返回。如果 ItemType
还不是 PAGE_BREAK
,则会抛出脚本异常。
弃踢回攻
PageBreakItem
- 分页符项
抛出
Error
- 如果内容不是分页符项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asParagraphTextItem()
将该项作为段落文本项返回。如果 ItemType
还不是 PARAGRAPH_TEXT
,则会抛出脚本异常。
弃踢回攻
ParagraphTextItem
:段落文本项
抛出
Error
- 如果项不是段落文本项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asScaleItem()
asSectionHeaderItem()
将内容作为版块标题项返回。如果 ItemType
还不是 SECTION_HEADER
,则会抛出脚本异常。
弃踢回攻
SectionHeaderItem
- 版块标题项
抛出
Error
- 如果该项不是小节标题项
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asTextItem()
asTimeItem()
duplicate()
getHelpText()
获取该项的帮助文本(有时称为 ImageItems
、PageBreakItems
和 SectionHeaderItems
等布局项的说明文本)。
弃踢回攻
String
- 项目的帮助文本或说明文本
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getId()
获取项的唯一标识符。
弃踢回攻
Integer
- 商品的 ID
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getIndex()
获取表单中所有项中的项的索引。
弃踢回攻
Integer
- 项的索引
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getTitle()
获取商品的标题(如果为 SectionHeaderItem
,则有时称为标题文本)。
弃踢回攻
String
- 商品的标题或标题文本
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getType()
setHelpText(text)
设置项的帮助文本(有时称为 ImageItems
、PageBreakItems
和 SectionHeaderItems
等布局项的说明文本)。
参数
名称 | 类型 | 说明 |
---|---|---|
text | String | 新的帮助文本 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setTitle(title)
设置项目的标题(如果为 SectionHeaderItem
,则有时称为标题文本)。
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 新标题或标题文字 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms