Class CardSection
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การ์ดส่วน
ส่วนการ์ดจะเก็บกลุ่มวิดเจ็ตไว้ด้วยกันและแยกวิดเจ็ตแต่ละรายการออกจากกัน
พร้อมใช้งานสำหรับส่วนเสริมของ Google Workspace และแอป Google Chat
const image = CardService.newImage();
// Build image ...
const textParagraph = CardService.newTextParagraph();
// Build text paragraph ...
const cardSection = CardService.newCardSection()
.setHeader('Section header')
.addWidget(image)
.addWidget(textParagraph);
เอกสารประกอบโดยละเอียด
setCollapseControl(collapseControl)
ตั้งค่าปุ่มขยายและยุบที่ปรับแต่งได้ของส่วน ปุ่มเหล่านี้จะแสดงก็ต่อเมื่อส่วนนั้นยุบได้ หากไม่ได้ตั้งค่าช่องนี้ ระบบจะใช้ปุ่มเริ่มต้น
พร้อมใช้งานสำหรับแอป Google Chat อยู่ในเวอร์ชันตัวอย่างสำหรับนักพัฒนาซอฟต์แวร์สำหรับส่วนเสริมของ Google Workspace
const collapseButton =
CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.BORDERLESS)
.setText('show less');
const expandButton =
CardService.newImageButton()
.setImageButtonStyle(CardService.ImageButtonStyle.FILLED)
.setMaterialIcon(CardService.newMaterialIcon().setName('bug_report'));
const collapsibleSection =
CardService.newCardSection()
.setCollapsible(true)
.setNumUncollapsibleWidgets(1)
.setCollapseControl(
CardService.newCollapseControl()
.setHorizontalAlign(CardService.HorizontalAlignment.CENTER)
.setCollapseButton(collapseButton)
.setExpandButton(expandButton),
);
พารามิเตอร์
รีเทิร์น
CardSection
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
setCollapsible(collapsible)
กำหนดว่าจะยุบส่วนได้หรือไม่
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
collapsible | Boolean | การตั้งค่าแบบยุบได้ |
รีเทิร์น
CardSection
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eCard sections visually separate groups of widgets within Google Workspace add-ons and Chat apps.\u003c/p\u003e\n"],["\u003cp\u003eThey can be customized with headers and configured to be collapsible, showing a specified number of widgets when collapsed.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can easily add widgets like images and text paragraphs to card sections using Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eCard sections enhance the organization and user experience by grouping related content within cards.\u003c/p\u003e\n"]]],[],null,["# Class CardSection\n\nCardSection\n\nA card section holds groups of widgets and provides visual separation between them.\n\nAvailable for Google Workspace add-ons and Google Chat apps.\n\n```javascript\nconst image = CardService.newImage();\n// Build image ...\nconst textParagraph = CardService.newTextParagraph();\n// Build text paragraph ...\n\nconst cardSection = CardService.newCardSection()\n .setHeader('Section header')\n .addWidget(image)\n .addWidget(textParagraph);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------------------------------------------------|------------------|---------------------------------------------------------------------------------|\n| [addWidget(widget)](#addWidget(Widget)) | [CardSection](#) | Adds the given widget to this section. |\n| [setCollapseControl(collapseControl)](#setCollapseControl(CollapseControl)) | [CardSection](#) | Sets the customizable expand and collapse buttons of the section. |\n| [setCollapsible(collapsible)](#setCollapsible(Boolean)) | [CardSection](#) | Sets whether the section can be collapsed. |\n| [setHeader(header)](#setHeader(String)) | [CardSection](#) | Sets the header of the section. |\n| [setNumUncollapsibleWidgets(numUncollapsibleWidgets)](#setNumUncollapsibleWidgets(Integer)) | [CardSection](#) | Sets the number of widgets that are still shown when this section is collapsed. |\n\nDetailed documentation\n----------------------\n\n### `add``Widget(widget)`\n\nAdds the given widget to this section. Widgets are shown in the order they were added. You\ncan't add more than 100 widgets to a card section.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|------------------------------------------------------|---------------------------------|\n| `widget` | [Widget](/apps-script/reference/card-service/widget) | A widget to add to the section. |\n\n#### Return\n\n\n[CardSection](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Collapse``Control(collapseControl)`\n\nSets the customizable expand and collapse buttons of the section. These buttons are shown only\nif the section is collapsible. If this field isn't set, default buttons are used.\n\nAvailable for Google Chat apps. In developer preview for Google Workspace add-ons.\n\n\n| **Developer Preview:** Available as part of the [Google Workspace Developer Preview Program](https://developers.google.com/workspace/preview), which grants early access to certain features.\n\n\u003cbr /\u003e\n\n```javascript\nconst collapseButton =\n CardService.newTextButton()\n .setTextButtonStyle(CardService.TextButtonStyle.BORDERLESS)\n .setText('show less');\n\nconst expandButton =\n CardService.newImageButton()\n .setImageButtonStyle(CardService.ImageButtonStyle.FILLED)\n .setMaterialIcon(CardService.newMaterialIcon().setName('bug_report'));\n\nconst collapsibleSection =\n CardService.newCardSection()\n .setCollapsible(true)\n .setNumUncollapsibleWidgets(1)\n .setCollapseControl(\n CardService.newCollapseControl()\n .setHorizontalAlign(CardService.HorizontalAlignment.CENTER)\n .setCollapseButton(collapseButton)\n .setExpandButton(expandButton),\n );\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------------|-------------------------------------------------------------------------|-------------------------------|\n| `collapse``Control` | [CollapseControl](/apps-script/reference/card-service/collapse-control) | The collapse control setting. |\n\n#### Return\n\n\n[CardSection](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Collapsible(collapsible)`\n\nSets whether the section can be collapsed.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|-----------|--------------------------|\n| `collapsible` | `Boolean` | The collapsible setting. |\n\n#### Return\n\n\n[CardSection](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Header(header)`\n\nSets the header of the section. Optional.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|----------|------------------|\n| `header` | `String` | The header text. |\n\n#### Return\n\n\n[CardSection](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Num``Uncollapsible``Widgets(numUncollapsibleWidgets)`\n\nSets the number of widgets that are still shown when this section is collapsed. The widgets\nshown are always the first ones that were added.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------------------------|-----------|--------------------------------|\n| `num``Uncollapsible``Widgets` | `Integer` | The number of widgets to show. |\n\n#### Return\n\n\n[CardSection](#) --- This object, for chaining."]]