一般表單項目,包含所有項目通用的屬性,例如標題和說明文字。您可以透過 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); }
實作類別
| 名稱 | 簡短說明 |
|---|
方法
內容詳盡的說明文件
as Checkbox Grid Item()
以核取方塊格線項目的形式傳回項目。如果 Item 尚未 CHECKBOX_GRID,就會擲回指令碼例外狀況。
回攻員
Checkbox:核取方塊格線項目
擲回
Error:如果項目不是核取方塊格線項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Checkbox Item()
以核取方塊項目形式傳回項目。如果 Item 尚未 CHECKBOX,就會擲回指令碼例外狀況。
回攻員
Checkbox:核取方塊項目
擲回
Error:如果項目不是核取方塊項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Date Item()
as Date Time Item()
以日期時間項目形式傳回項目。如果 Item 尚未 DATETIME,就會擲回指令碼例外狀況。
回攻員
Date - 日期時間項目
擲回
Error:如果項目不是日期時間項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Duration Item()
傳回項目做為時間長度項目。如果 Item 尚未 DURATION,就會擲回指令碼例外狀況。
回攻員
Duration:時間長度項目
擲回
Error - 如果項目不是時間長度項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Grid Item()
as List Item()
as Multiple Choice Item()
傳回項目做為複選項目。如果 Item 尚未 MULTIPLE_CHOICE,就會擲回指令碼例外狀況。
回攻員
Multiple:複選題項目
擲回
Error - 如果項目不是複選題
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Page Break Item()
傳回項目做為分頁符項目。如果 Item 尚未 PAGE_BREAK,就會擲回指令碼例外狀況。
回攻員
Page:分頁符號項目
擲回
Error - 如果項目不是分頁符項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Paragraph Text Item()
將項目傳回為段落文字項目。如果 Item 尚未 PARAGRAPH_TEXT,就會擲回指令碼例外狀況。
回攻員
Paragraph:段落文字項目
擲回
Error:如果項目不是段落文字項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Rating Item()
將項目傳回為評分項目。如果 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
as Scale Item()
as Section Header Item()
將項目傳回為區段標題項目。如果 Item 尚未 SECTION_HEADER,就會擲回指令碼例外狀況。
回攻員
Section:區段標題項目
擲回
Error:如果項目不是區段標題項目
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
as Text Item()
as Time Item()
duplicate()
get Help Text()
取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 Image、Page 和 Section)。
回攻員
String:項目的說明文字
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Id()
取得項目的專屬 ID。
回攻員
Integer:商品的 ID
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Index()
取得表單中所有項目中的項目索引。
回攻員
Integer:項目的索引
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Title()
取得項目的標題 (如果是 Section,有時稱為標題文字)。
回攻員
String:項目的標題或標頭文字
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Type()
set Help Text(text)
設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 Image、Page 和 Section)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 新的說明文字 |
回攻員
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Title(title)
設定項目的標題 (如果是 Section,有時也稱為標題文字)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
title | String | 新標題或標頭文字 |
回攻員
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms