Class GridItem

GridItem

以欄和列的方格形式呈現問題項目,讓受訪者從一連串的圓形按鈕中,為每一列選取一個選項。您可以從 Form 存取或建立項目。

// Open a form by ID and add a new grid item.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const item = form.addGridItem();
item.setTitle('Rate your interests')
    .setRows(['Cars', 'Computers', 'Celebrities'])
    .setColumns(['Boring', 'So-so', 'Interesting']);

方法

方法傳回類型簡短說明
clearValidation()GridItem移除這個格線項目的所有資料驗證。
createResponse(responses)ItemResponse為這個格線項目建立新的 ItemResponse
duplicate()GridItem建立這個項目的副本,並附加到表單結尾。
getColumns()String[]取得格線中每個資料欄的值。
getHelpText()String取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。
getId()Integer取得項目的專屬 ID。
getIndex()Integer取得表單中所有項目中的項目索引。
getRows()String[]取得格線中每個資料列的值。
getTitle()String取得項目的標題 (如果是 SectionHeaderItem,有時稱為標題文字)。
getType()ItemType取得項目的類型,以 ItemType 表示。
isRequired()Boolean決定受訪者是否必須回答問題。
setColumns(columns)GridItem根據值陣列設定格線的資料欄。
setHelpText(text)GridItem設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。
setRequired(enabled)GridItem設定受訪者是否必須回答問題。
setRows(rows)GridItem根據值陣列設定格線的資料列。
setTitle(title)GridItem設定項目的標題 (如果是 SectionHeaderItem,有時稱為標題文字)。
setValidation(validation)GridItem為這個格線項目設定資料驗證。

內容詳盡的說明文件

clearValidation()

移除這個格線項目的所有資料驗證。

回攻員

GridItem - 這個項目,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

createResponse(responses)

為這個格線項目建立新的 ItemResponse。引數 responses 必須是 String[] 陣列,內含的值數量與格線中的列數相同。如果格狀問題並非必填,則 null 元素表示該列沒有回覆。如果任何值不符合有效選項,就會擲回例外狀況。

參數

名稱類型說明
responsesString[]這個格狀檢視項目的一組有效答案

回攻員

ItemResponse - 項目回應

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

duplicate()

建立這個項目的副本,並附加到表單結尾。

回攻員

GridItem:這個 GridItem 的副本,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getColumns()

取得格線中每個資料欄的值。

回攻員

String[]:資料欄值陣列,受訪者查看表單時會看到這些值做為標籤

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getHelpText()

取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。

回攻員

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

getRows()

取得格線中每個資料列的值。

回攻員

String[]:列值的陣列,受訪者查看表單時會看到這些值做為標籤

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • 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()

取得項目的類型,以 ItemType 表示。

回攻員

ItemType:項目的類型

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

isRequired()

決定受訪者是否必須回答問題。

回攻員

Boolean:受訪者是否必須回答問題

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setColumns(columns)

根據值陣列設定格線的資料欄。如果指定陣列為空,就會擲回例外狀況。

參數

名稱類型說明
columnsString[]資料欄值陣列,受訪者查看表單時會看到這些值做為標籤

回攻員

GridItem - 這個項目,用於鏈結

擲回

Error:如果指定陣列為 null 或空白

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setHelpText(text)

設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。

參數

名稱類型說明
textString新的說明文字

回攻員

GridItem - this GridItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setRequired(enabled)

設定受訪者是否必須回答問題。

參數

名稱類型說明
enabledBoolean受訪者是否必須回答問題

回攻員

GridItem - 目前項目 (用於鏈結)

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setRows(rows)

根據值陣列設定格線的資料列。如果指定陣列為空白,就會擲回例外狀況。

參數

名稱類型說明
rowsString[]資料列值陣列,受訪者查看表單時會看到這些值做為標籤

回攻員

GridItem - 這個項目,用於鏈結

擲回

Error:如果指定陣列為 null 或空白

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setTitle(title)

設定項目的標題 (如果是 SectionHeaderItem,有時稱為標題文字)。

參數

名稱類型說明
titleString新標題或標頭文字

回攻員

GridItem - this GridItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setValidation(validation)

為這個格線項目設定資料驗證。傳遞 null 或未呼叫任何必要函式的 GridValidation 執行個體,會移除任何先前的驗證。

參數

名稱類型說明
validationGridValidation要套用至這個項目的 GridValidation。

回攻員

GridItem - this GridItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms