Class Group
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Groupe
Accéder aux groupes de feuilles de calcul et les modifier. Les groupes sont une association entre un intervalle de lignes ou de colonnes contiguës qui peuvent être développées ou réduites en tant qu'unité pour masquer/afficher les lignes ou les colonnes.
Chaque groupe comporte un bouton d'activation/désactivation sur la ligne ou la colonne qui le précède ou le suit directement (selon les paramètres). Il permet de développer ou de réduire le groupe dans son ensemble.
La profondeur d'un groupe fait référence à la position imbriquée du groupe et au nombre de groupes plus importants qui le contiennent. L'état réduit d'un groupe indique si le groupe doit rester réduit ou développé après le développement d'un groupe parent. De plus, lorsqu'un groupe est réduit ou développé, les lignes ou colonnes qu'il contient sont masquées ou rendues visibles. Toutefois, des lignes ou colonnes individuelles peuvent être masquées ou rendues visibles indépendamment de l'état réduit.
Documentation détaillée
collapse()
Réduit ce groupe.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Collapses this group.
group.collapse();
Renvois
Group
: ce groupe, pour le chaînage.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand()
Développe ce groupe.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Expands this group.
group.expand();
Renvois
Group
: ce groupe, pour le chaînage.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getControlIndex()
Renvoie l'index du bouton bascule de contrôle de ce groupe. Il s'agit de l'index juste avant la plage lorsque le bouton de contrôle est affiché avant le groupe, ou de l'index juste après la plage dans le cas contraire.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
sheet.setRowGroupControlAfter(true);
const range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Returns 4
const controlIndex = group.getControlIndex();
Renvois
Integer
: index du bouton bascule de contrôle de ce groupe.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDepth()
Renvoie la profondeur de ce groupe.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Returns 1 if the group is at depth 1.
const depth = group.getDepth();
Renvois
Integer
: profondeur de ce groupe.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange()
Renvoie la plage sur laquelle ce groupe existe.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
let range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(1, 1);
// Returns the range 2:3 if the group is over rows 2:3
range = group.getRange();
Renvois
Range
: plage sur laquelle le groupe existe.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isCollapsed()
Renvoie true
si ce groupe est réduit.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Returns true if the group is collapsed.
const isCollapsed = group.isCollapsed();
Renvois
Boolean
: true
si ce groupe est réduit, false
sinon.
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove()
Supprime ce groupe de la feuille, ce qui réduit la profondeur du groupe de range
d'une unité. Cela peut modifier d'autres groupes. Après l'appel, l'objet de groupe devient inutilisable.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
let range = sheet.getRange('2:3');
range.shiftRowGroupDepth(1);
const group = sheet.getRowGroup(2, 1);
// Removes this group
range = group.remove();
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des scopes suivants :
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
Voir aussi
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/13 (UTC).
[null,null,["Dernière mise à jour le 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,["# Class Group\n\nGroup\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\n### Methods\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\n### `collapse()`\n\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\n#### Return\n\n\n[Group](#) --- This group, for chaining.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n[Group](#) --- This group, for chaining.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n`Integer` --- The control toggle index of this group.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n`Integer` --- The depth of this group.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- The range over which the group exists.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n`Boolean` --- `true` If this group is collapsed; returns `false` otherwise.\n\n#### Authorization\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()`\n\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\n#### Authorization\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#### See also\n\n- [Range.shiftRowGroupDepth(delta)](/apps-script/reference/spreadsheet/range#shiftRowGroupDepth(Integer))\n- [Range.shiftColumnGroupDepth(delta)](/apps-script/reference/spreadsheet/range#shiftColumnGroupDepth(Integer))"]]