Class CardHeader

CardHeader

Card 的標頭。

適用於 Google Workspace 外掛程式和 Google Chat 應用程式。

var cardHeader = CardService.newCardHeader()
    .setTitle("Card header title")
    .setSubtitle("Card header subtitle")
    .setImageStyle(CardService.ImageStyle.CIRCLE)
    .setImageUrl("https://image.png");

方法

方法傳回類型簡短說明
setImageAltText(imageAltText)CardHeader設定標題圖片的替代文字。
setImageStyle(imageStyle)CardHeader設定資訊卡標頭中的圖示裁剪。
setImageUrl(imageUrl)CardHeader提供網址或資料字串,將圖片設為要在標頭中使用。
setSubtitle(subtitle)CardHeader設定資訊卡標頭的副標題。
setTitle(title)CardHeader設定資訊卡標頭的標題。

內容詳盡的說明文件

setImageAltText(imageAltText)

設定標題圖片的替代文字。

參數

名稱類型說明
imageAltTextString標題圖片的替代文字。

回攻員

CardHeader:這個物件用於鏈結。


setImageStyle(imageStyle)

設定資訊卡標頭中的圖示裁剪。預設為無裁剪。選用。

參數

名稱類型說明
imageStyleImageStyle樣式設定。

回攻員

CardHeader:這個物件用於鏈結。


setImageUrl(imageUrl)

提供網址或資料字串,將圖片設為要在標頭中使用。

提供的網址可以是可公開存取的網址,或是採用 Base64 編碼的圖片字串。如要取得後者,您可以使用以下程式碼,從 Google 雲端硬碟中的圖片建立編碼的圖片字串,然後儲存該字串,以搭配 setImageUrl(imageUrl) 使用。這個方法可避免外掛程式需要存取公開可用圖片網址:

// The following assumes you have the image to use in Google Drive and have its ID.
var imageBytes = DriveApp.getFileById(imageID).getBlob().getBytes();
var encodedImageURL = "data:image/jpeg;base64," + Utilities.base64Encode(imageBytes);

// You can store encodeImageURL and use it as a parameter to CardHeader.setImageUrl(imageUrl).

參數

名稱類型說明
imageUrlString要使用的代管圖片網址,或已編碼的圖片字串。

回攻員

CardHeader:這個物件用於鏈結。


setSubtitle(subtitle)

設定資訊卡標頭的副標題。選用。

參數

名稱類型說明
subtitleString標題副標題文字。

回攻員

CardHeader:這個物件用於鏈結。


setTitle(title)

設定資訊卡標頭的標題。這是必填欄位。

參數

名稱類型說明
titleString標題文字。

回攻員

CardHeader:這個物件用於鏈結。