Class Group Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Spreadsheet groups associate contiguous rows or columns that can be expanded or collapsed to hide or show content.
Each group has a control toggle to expand or collapse the group as a whole.
The depth of a group indicates its nested position within larger groups.
The collapsed state determines if a group remains collapsed or expanded after a parent group is expanded.
Groups can be manipulated using methods like collapse(), expand(), and remove().
Access and modify spreadsheet groups. Groups are an association between an interval of contiguousrows or columns that can be expanded or collapsed as a unit to hide/show the rows or columns.Each group has acontrol toggle on the row or column directly before or after the group(depending on settings) that can expand or collapse the group as a whole.
Thedepth of a group refers to the nested position of the group and how many largergroups contain the group. Thecollapsed state of a group refers to whether the groupshould remain collapsed or expanded after a parent group has been expanded. Additionally, at thetime that a group is collapsed or expanded, the rows or columns within the group are hidden orset visible, though individual rows or columns can be hidden or set visible irrespective of thecollapsed state.
Methods
| Method | Return type | Brief description |
|---|---|---|
collapse() | Group | Collapses this group. |
expand() | Group | Expands this group. |
get | Integer | Returns the control toggle index of this group. |
get | Integer | Returns the depth of this group. |
get | Range | Returns the range over which this group exists. |
is | Boolean | Returnstrue if this group is collapsed. |
remove() | void | Removes this group from the sheet, reducing the group depth of therange byone. |
Detailed documentation
collapse()
Collapses this group.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Collapses this group.group.collapse();
Return
Group — This group, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
expand()
Expands this group.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Expands this group.group.expand();
Return
Group — This group, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getControlIndex()
Returns the control toggle index of this group. This is the index just before the range whenthe control toggle is shown before the group, or the index just after the range otherwise.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];sheet.setRowGroupControlAfter(true);constrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Returns 4constcontrolIndex=group.getControlIndex();
Return
Integer — The control toggle index of this group.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getDepth()
Returns the depth of this group.
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();
Return
Integer — The depth of this group.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getRange()
Returns the range over which this group exists.
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();
Return
Range — The range over which the group exists.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
isCollapsed()
Returnstrue if this group is collapsed.
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();
Return
Boolean —true If this group is collapsed; returnsfalse otherwise.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
remove()
Removes this group from the sheet, reducing the group depth of therange byone. This may modify other groups. After calling this, the group object becomes invalid to use.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];letrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Removes this grouprange=group.remove();
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
See also
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.