通用表單項目,包含所有項目的共同屬性,例如標題和說明文字。您可以透過 Form
存取或建立項目。
如要針對特定類型的屬性運作,請使用 get
檢查項目的 Item
,然後使用 as
等方法將項目轉換為適當的類別。
// Create a new form and add a text item.
const form = FormApp.create('Form Name');
form.addTextItem();
// Access the text item as a generic item.
const items = form.getItems();
const item = items[0];
// Cast the generic item to the text-item class.
if (item.getType() === 'TEXT') {
const textItem = item.asTextItem();
textItem.setRequired(false);
}
實作類別
名稱 | 簡短說明 |
---|
方法
內容詳盡的說明文件
asCheckboxGridItem()
以核取方塊格線項目形式傳回項目。如果 Item
尚未 CHECKBOX_GRID
,就會擲回指令碼例外狀況。
回攻員
Checkbox
:核取方塊格線項目
擲回
Error
:如果項目不是核取方塊格線項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asCheckboxItem()
以核取方塊項目的形式傳回項目。如果 Item
尚未 CHECKBOX
,就會擲回指令碼例外狀況。
回攻員
Checkbox
:核取方塊項目
擲回
Error
:如果項目不是核取方塊項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asDateItem()
asDateTimeItem()
將項目傳回為日期/時間項目。如果 Item
尚未 DATETIME
,就會擲回指令碼例外狀況。
回攻員
Date
:日期時間項目
擲回
Error
:如果項目不是日期/時間項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asDurationItem()
將項目傳回為時間長度項目。如果 Item
尚未 DURATION
,就會擲回指令碼例外狀況。
回攻員
Duration
:時間長度項目
擲回
Error
:如果項目不是時間長度項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asGridItem()
asListItem()
asMultipleChoiceItem()
asPageBreakItem()
將項目傳回為分頁項目。如果 Item
尚未 PAGE_BREAK
,就會擲回指令碼例外狀況。
回攻員
Page
:分頁項目
擲回
Error
:如果項目不是分頁項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asParagraphTextItem()
以段落文字項目形式傳回項目。如果 Item
尚未 PARAGRAPH_TEXT
,就會擲回指令碼例外狀況。
回攻員
Paragraph
- 段落文字項目
擲回
Error
:如果項目不是段落文字項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asRatingItem()
以評分項目形式傳回項目。如果 Item
尚未 RATING
,就會擲回 ScriptingException。
// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');
// Fetch any item which is of type rating.
const item = form.getItems(FormApp.ItemType.RATING)[0];
// Convert the item to a rating item.
const ratingItem = item.asRatingItem();
回攻員
Rating
:評分項目。
擲回
Error
:如果項目不是評分項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asScaleItem()
asSectionHeaderItem()
以區段標題項目形式傳回項目。如果 Item
尚未 SECTION_HEADER
,就會擲回指令碼例外狀況。
回攻員
Section
- 區段標題項目
擲回
Error
:如果項目不是區段標題項目
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
asTextItem()
asTimeItem()
duplicate()
getHelpText()
取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 Image
、Page
和 Section
)。
回攻員
String
:項目的說明文字或說明文字
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getId()
取得項目的專屬 ID。
回攻員
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()
取得項目的標題 (在 Section
的情況下,有時稱為標頭文字)。
回攻員
String
:項目的標題或標頭文字
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getType()
setHelpText(text)
設定項目的說明文字 (對於 Image
、Page
和 Section
等版面配置項目,有時稱為說明文字)。
參數
名稱 | 類型 | 說明 |
---|---|---|
text | String | 新的說明文字 |
回攻員
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setTitle(title)
設定項目的標題 (在 Section
的情況下,有時稱為標頭文字)。
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 新的標題或標頭文字 |
回攻員
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms