Tetap teratur dengan koleksi Simpan dan kategorikan konten berdasarkan preferensi Anda.
Group
Mengakses dan mengubah grup spreadsheet. Grup adalah asosiasi antara interval baris atau kolom yang berdekatan yang dapat diluaskan atau diciutkan sebagai satu unit untuk menyembunyikan/menampilkan baris atau kolom. Setiap grup memiliki tombol kontrol di baris atau kolom tepat sebelum atau setelah grup (bergantung pada setelan) yang dapat meluaskan atau menciutkan grup secara keseluruhan.
Kedalaman grup mengacu pada posisi bertingkat grup dan jumlah grup yang lebih besar yang berisi grup tersebut. Status diciutkan grup mengacu pada apakah grup harus tetap diciutkan atau diluaskan setelah grup induk diluaskan. Selain itu, saat grup diciutkan atau diperluas, baris atau kolom dalam grup disembunyikan atau diatur agar terlihat, meskipun baris atau kolom individual dapat disembunyikan atau diatur agar terlihat terlepas dari status ciut.
Menghapus grup ini dari sheet, sehingga mengurangi kedalaman grup range sebanyak satu.
Dokumentasi mendetail
collapse()
Menciutkan grup ini.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Collapses this group.group.collapse();
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Expands this group.group.expand();
Menampilkan indeks tombol kontrol grup ini. Ini adalah indeks tepat sebelum rentang saat tombol kontrol ditampilkan sebelum grup, atau indeks tepat setelah rentang.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Returns 1 if the group is at depth 1.constdepth=group.getDepth();
Pulang pergi
Integer — Kedalaman grup ini.
Otorisasi
Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];letrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(1,1);// Returns the range 2:3 if the group is over rows 2:3range=group.getRange();
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Returns true if the group is collapsed.constisCollapsed=group.isCollapsed();
Pulang pergi
Boolean — true Jika grup ini diciutkan; menampilkan false jika tidak.
Otorisasi
Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:
Menghapus grup ini dari sheet, sehingga mengurangi kedalaman grup range sebanyak satu. Tindakan ini dapat mengubah grup lain. Setelah memanggilnya, objek grup menjadi tidak valid untuk digunakan.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];letrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Removes this grouprange=group.remove();
Otorisasi
Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-13 UTC."],[[["\u003cp\u003eGroups in Google Sheets allow you to associate contiguous rows or columns, enabling them to be expanded or collapsed as a single unit to control visibility.\u003c/p\u003e\n"],["\u003cp\u003eEach group has a control toggle located before or after the group, which dictates whether the group is expanded or collapsed, affecting the visibility of its rows or columns.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGroup\u003c/code\u003e class in Apps Script provides methods to programmatically manage groups, including collapsing, expanding, retrieving group properties, and removing groups.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGroup\u003c/code\u003e methods like \u003ccode\u003ecollapse()\u003c/code\u003e, \u003ccode\u003eexpand()\u003c/code\u003e, \u003ccode\u003egetControlIndex()\u003c/code\u003e, \u003ccode\u003egetDepth()\u003c/code\u003e, \u003ccode\u003egetRange()\u003c/code\u003e, \u003ccode\u003eisCollapsed()\u003c/code\u003e, and \u003ccode\u003eremove()\u003c/code\u003e offer control over group behavior and properties within your scripts.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing these methods allows for dynamic manipulation of spreadsheet groups, enhancing the interactivity and organization of your spreadsheet data through automation.\u003c/p\u003e\n"]]],[],null,["Group\n\nAccess and modify spreadsheet groups. Groups are an association between an interval of contiguous\nrows or columns that can be expanded or collapsed as a unit to hide/show the rows or columns.\nEach group has a *control toggle* on the row or column directly before or after the group\n(depending on settings) that can expand or collapse the group as a whole.\n\nThe *depth* of a group refers to the nested position of the group and how many larger\ngroups contain the group. The *collapsed state* of a group refers to whether the group\nshould remain collapsed or expanded after a parent group has been expanded. Additionally, at the\ntime that a group is collapsed or expanded, the rows or columns within the group are hidden or\nset visible, though individual rows or columns can be hidden or set visible irrespective of the\ncollapsed state. \n\nMethods\n\n| Method | Return type | Brief description |\n|-----------------------------------------|---------------------------------------------------|-------------------------------------------------------------------------------------------------|\n| [collapse()](#collapse()) | [Group](#) | Collapses this group. |\n| [expand()](#expand()) | [Group](#) | Expands this group. |\n| [getControlIndex()](#getControlIndex()) | `Integer` | Returns the control toggle index of this group. |\n| [getDepth()](#getDepth()) | `Integer` | Returns the depth of this group. |\n| [getRange()](#getRange()) | [Range](/apps-script/reference/spreadsheet/range) | Returns the range over which this group exists. |\n| [isCollapsed()](#isCollapsed()) | `Boolean` | Returns `true` if this group is collapsed. |\n| [remove()](#remove()) | `void` | Removes this group from the sheet, reducing the group depth of the [range](#getRange()) by one. |\n\nDetailed documentation \n\n`collapse()` \nCollapses this group.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nconst range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Collapses this group.\ngroup.collapse();\n```\n\nReturn\n\n\n[Group](#) --- this group, for chaining\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`expand()` \nExpands this group.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nconst range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Expands this group.\ngroup.expand();\n```\n\nReturn\n\n\n[Group](#) --- this group, for chaining\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Control``Index()` \nReturns the control toggle index of this group. This is the index just before the range when\nthe control toggle is shown before the group, or the index just after the range otherwise.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nsheet.setRowGroupControlAfter(true);\nconst range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Returns 4\nconst controlIndex = group.getControlIndex();\n```\n\nReturn\n\n\n`Integer` --- the control toggle index of this group\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Depth()` \nReturns the depth of this group.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nconst range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Returns 1 if the group is at depth 1.\nconst depth = group.getDepth();\n```\n\nReturn\n\n\n`Integer` --- the depth of this group\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Range()` \nReturns the range over which this group exists.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nlet range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(1, 1);\n\n// Returns the range 2:3 if the group is over rows 2:3\nrange = group.getRange();\n```\n\nReturn\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- the range over which the group exists\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`is``Collapsed()` \nReturns `true` if this group is collapsed.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nconst range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Returns true if the group is collapsed.\nconst isCollapsed = group.isCollapsed();\n```\n\nReturn\n\n\n`Boolean` --- `true` if this group is collapsed; returns `false` otherwise\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`remove()` \nRemoves this group from the sheet, reducing the group depth of the [range](#getRange()) by\none. This may modify other groups. After calling this, the group object becomes invalid to use.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];\nlet range = sheet.getRange('2:3');\nrange.shiftRowGroupDepth(1);\nconst group = sheet.getRowGroup(2, 1);\n\n// Removes this group\nrange = group.remove();\n```\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\nSee also\n\n- [Range.shiftRowGroupDepth(delta)](/apps-script/reference/spreadsheet/range#shiftRowGroupDepth(Integer))\n- [Range.shiftColumnGroupDepth(delta)](/apps-script/reference/spreadsheet/range#shiftColumnGroupDepth(Integer))"]]