Class CardHeader
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
카드헤더
Card
의 헤더입니다.
Google Workspace 부가기능 및 Google Chat 앱에서 사용할 수 있습니다.
const cardHeader = CardService.newCardHeader()
.setTitle('Card header title')
.setSubtitle('Card header subtitle')
.setImageStyle(CardService.ImageStyle.CIRCLE)
.setImageUrl('https://image.png');
자세한 문서
setImageAltText(imageAltText)
헤더 이미지의 대체 텍스트를 설정합니다.
매개변수
이름 | 유형 | 설명 |
imageAltText | String | 헤더 이미지의 대체 텍스트입니다. |
리턴
CardHeader
: 연결을 위한 객체입니다.
setImageStyle(imageStyle)
카드 헤더의 아이콘 자르기를 설정합니다. 기본값은 자르지 않음입니다. 선택사항입니다.
매개변수
리턴
CardHeader
: 연결을 위한 객체입니다.
setImageUrl(imageUrl)
URL 또는 데이터 문자열을 제공하여 헤더에 사용할 이미지를 설정합니다.
제공된 URL은 공개적으로 액세스 가능한 URL 또는 base64로 인코딩된 이미지 문자열일 수 있습니다.
후자를 얻으려면 다음 코드를 사용하여 Google Drive의 이미지에서 인코딩된 이미지 문자열을 만든 다음 나중에 setImageUrl(imageUrl)
와 함께 사용할 수 있도록 이 문자열을 저장하면 됩니다. 이 방법을 사용하면 부가기능이 공개적으로 사용 가능한 이미지 URL에 액세스할 필요가 없습니다.
// The following assumes you have the image to use in Google Drive and have its
// ID.
const imageBytes = DriveApp.getFileById('123abc').getBlob().getBytes();
const encodedImageURL =
`data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;
// You can store encodeImageURL and use it as a parameter to
// CardHeader.setImageUrl(imageUrl).
매개변수
이름 | 유형 | 설명 |
imageUrl | String | 사용할 호스팅된 이미지의 URL 주소 또는 인코딩된 이미지 문자열입니다. |
리턴
CardHeader
: 연결을 위한 객체입니다.
setSubtitle(subtitle)
카드 헤더의 부제목을 설정합니다. 선택사항입니다.
매개변수
이름 | 유형 | 설명 |
subtitle | String | 헤더 부제목 텍스트입니다. |
리턴
CardHeader
: 연결을 위한 객체입니다.
setTitle(title)
카드 헤더의 제목을 설정합니다. 필수 항목입니다.
매개변수
이름 | 유형 | 설명 |
title | String | 헤더 텍스트입니다. |
리턴
CardHeader
: 연결을 위한 객체입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eCardHeader\u003c/code\u003e objects allow you to customize the header of a card, including title, subtitle, and image, within Google Workspace Add-ons and Google Chat apps.\u003c/p\u003e\n"],["\u003cp\u003eYou can set an image for the header using \u003ccode\u003esetImageUrl()\u003c/code\u003e by providing a public URL or a base64 encoded image string.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003esetTitle()\u003c/code\u003e and \u003ccode\u003esetSubtitle()\u003c/code\u003e allow you to define the main text and supporting text for the header, respectively.\u003c/p\u003e\n"],["\u003cp\u003eCustomize the image display with \u003ccode\u003esetImageStyle()\u003c/code\u003e to control cropping and use \u003ccode\u003esetImageAltText()\u003c/code\u003e to provide alternative text for accessibility.\u003c/p\u003e\n"]]],["The `CardHeader` object allows customization of a card's header in Google Workspace add-ons and Google Chat apps. Key actions include setting the header's title using `setTitle()`, a subtitle with `setSubtitle()`, and an image via `setImageUrl()`. The image's appearance can be modified with `setImageStyle()` for cropping and `setImageAltText()` for alternative text. Image URLs can be direct links or base64 encoded strings. Each method returns the `CardHeader` object, enabling method chaining.\n"],null,["# Class CardHeader\n\nCardHeader\n\nThe header of a [Card](/apps-script/reference/card-service/card).\n\nAvailable for Google Workspace add-ons and Google Chat apps.\n\n```javascript\nconst cardHeader = CardService.newCardHeader()\n .setTitle('Card header title')\n .setSubtitle('Card header subtitle')\n .setImageStyle(CardService.ImageStyle.CIRCLE)\n .setImageUrl('https://image.png');\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------|-----------------|--------------------------------------------------------------------------|\n| [setImageAltText(imageAltText)](#setImageAltText(String)) | [CardHeader](#) | Sets the alternative text for the header image. |\n| [setImageStyle(imageStyle)](#setImageStyle(ImageStyle)) | [CardHeader](#) | Sets the cropping of the icon in the card header. |\n| [setImageUrl(imageUrl)](#setImageUrl(String)) | [CardHeader](#) | Sets the image to use in the header by providing its URL or data string. |\n| [setSubtitle(subtitle)](#setSubtitle(String)) | [CardHeader](#) | Sets the subtitle of the card header. |\n| [setTitle(title)](#setTitle(String)) | [CardHeader](#) | Sets the title of the card header. |\n\nDetailed documentation\n----------------------\n\n### `set``Image``Alt``Text(imageAltText)`\n\nSets the alternative text for the header image.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------------|----------|--------------------------------------------|\n| `image``Alt``Text` | `String` | The alternative text for the header image. |\n\n#### Return\n\n\n[CardHeader](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Image``Style(imageStyle)`\n\nSets the cropping of the icon in the card header. Defaults to no crop. Optional.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------|---------------------------------------------------------------|--------------------|\n| `image``Style` | [ImageStyle](/apps-script/reference/card-service/image-style) | The style setting. |\n\n#### Return\n\n\n[CardHeader](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Image``Url(imageUrl)`\n\nSets the image to use in the header by providing its URL or data string.\n\nThe provided URL can either be a publicly accessible URL or a base64 encoded image string.\nTo obtain the latter, you can use the following code to create an encoded image string from an\nimage in your Google Drive, then store that string for later use with [setImageUrl(imageUrl)](#setImageUrl(String)). This method prevents the need for your add-on to access a publicly\navailable image URL:\n\n```javascript\n// The following assumes you have the image to use in Google Drive and have its\n// ID.\nconst imageBytes = DriveApp.getFileById('123abc').getBlob().getBytes();\nconst encodedImageURL =\n `data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;\n\n// You can store encodeImageURL and use it as a parameter to\n// CardHeader.setImageUrl(imageUrl).\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|-----------------------------------------------------------------------|\n| `image``Url` | `String` | The URL address of a hosted image to use, or an encoded image string. |\n\n#### Return\n\n\n[CardHeader](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Subtitle(subtitle)`\n\nSets the subtitle of the card header. Optional.\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|---------------------------|\n| `subtitle` | `String` | The header subtitle text. |\n\n#### Return\n\n\n[CardHeader](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Title(title)`\n\nSets the title of the card header. Required.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|------------------|\n| `title` | `String` | The header text. |\n\n#### Return\n\n\n[CardHeader](#) --- This object, for chaining."]]