Zadbaj o dobrą organizację dzięki kolekcji Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Grupa
Dostęp do grup arkuszy kalkulacyjnych i ich modyfikowanie. Grupy to powiązanie między przedziałem sąsiadujących wierszy lub kolumn, które można rozwijać lub zwijać jako całość, aby ukrywać lub wyświetlać wiersze lub kolumny. Każda grupa ma przełącznik sterowania w wierszu lub kolumnie bezpośrednio przed lub za grupą (w zależności od ustawień), który umożliwia rozwinięcie lub zwinięcie całej grupy.
Głębokość grupy odnosi się do jej pozycji w strukturze zagnieżdżonej i liczby większych grup, które ją zawierają. Stan zwinięcia grupy określa, czy grupa powinna pozostać zwinięta czy rozwinięta po rozwinięciu grupy nadrzędnej. Dodatkowo w momencie zwinięcia lub rozwinięcia grupy wiersze lub kolumny w grupie są ukrywane lub ustawiane jako widoczne, chociaż poszczególne wiersze lub kolumny można ukrywać lub ustawiać jako widoczne niezależnie od stanu zwinięcia.
Usuwa tę grupę z arkusza, zmniejszając głębokość grupy range o 1.
Szczegółowa dokumentacja
collapse()
Zwija tę grupę.
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();
Zwraca indeks przełącznika sterowania tej grupy. Jest to indeks tuż przed zakresem, gdy przełącznik sterujący jest wyświetlany przed grupą, lub indeks tuż po zakresie w innych przypadkach.
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();
Powrót
Integer – głębokość tej grupy.
Autoryzacja
Skrypty korzystające z tej metody wymagają autoryzacji z użyciem co najmniej jednego z tych zakresów:
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();
Zwraca wartość true, jeśli ta grupa jest zwinięta.
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();
Powrót
Boolean – true Jeśli grupa jest zwinięta, zwraca wartość false, w przeciwnym razie zwraca wartość false.
Autoryzacja
Skrypty korzystające z tej metody wymagają autoryzacji z użyciem co najmniej jednego z tych zakresów:
Usuwa tę grupę z arkusza, zmniejszając głębokość grupy range o 1. Może to zmodyfikować inne grupy. Po wywołaniu tej funkcji obiekt grupy staje się nieprawidłowy.
constsheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];letrange=sheet.getRange('2:3');range.shiftRowGroupDepth(1);constgroup=sheet.getRowGroup(2,1);// Removes this grouprange=group.remove();
Autoryzacja
Skrypty korzystające z tej metody wymagają autoryzacji z użyciem co najmniej jednego z tych zakresów:
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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))"]]