Class Group
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
المجموعة
الوصول إلى مجموعات جداول البيانات وتعديلها المجموعات هي ارتباط بين فاصل زمني من الصفوف أو الأعمدة المتجاورة التي يمكن توسيعها أو تصغيرها كوحدة واحدة لإخفاء الصفوف أو الأعمدة أو عرضها.
تحتوي كل مجموعة على زر تحكّم في الصف أو العمود قبل المجموعة أو بعدها مباشرةً (حسب الإعدادات) يمكنه توسيع المجموعة أو تصغيرها ككل.
يشير عمق المجموعة إلى موضع المجموعة المتداخل وعدد المجموعات الأكبر التي تحتوي على المجموعة. تشير الحالة المصغّرة للمجموعة إلى ما إذا كان يجب أن تظل المجموعة مصغّرة أو موسّعة بعد توسيع المجموعة الرئيسية. بالإضافة إلى ذلك، عند تصغير مجموعة أو توسيعها، يتم إخفاء الصفوف أو الأعمدة داخل المجموعة أو ضبطها على مرئية، على الرغم من أنّه يمكن إخفاء الصفوف أو الأعمدة الفردية أو ضبطها على مرئية بغض النظر عن حالة التصغير.
الطُرق
الطريقة | نوع القيمة التي يتم إرجاعها | وصف قصير |
collapse() | Group | يصغّر هذه المجموعة. |
expand() | Group | توسيع هذه المجموعة |
getControlIndex() | Integer | تعرض هذه السمة فهرس زر التبديل الخاص بعنصر التحكّم في هذه المجموعة. |
getDepth() | Integer | تعرض هذه السمة عمق هذه المجموعة. |
getRange() | Range | تعرِض النطاق الذي توجد فيه هذه المجموعة. |
isCollapsed() | Boolean | تعرِض هذه السمة القيمة true إذا كانت هذه المجموعة مصغّرة. |
remove() | void | تؤدي هذه السمة إلى إزالة هذه المجموعة من الورقة، ما يؤدي إلى تقليل عمق المجموعة في range بمقدار واحد. |
مستندات مفصّلة
collapse()
يصغّر هذه المجموعة.
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();
الإرجاع
Group
: هذه المجموعة مخصّصة للربط.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand()
توسيع هذه المجموعة
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();
الإرجاع
Group
: هذه المجموعة مخصّصة للربط.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getControlIndex()
تعرض هذه السمة فهرس زر التبديل الخاص بعنصر التحكّم في هذه المجموعة. هذا هو الفهرس الذي يسبق النطاق مباشرةً عندما يظهر مفتاح التبديل الخاص بعنصر التحكّم قبل المجموعة، أو الفهرس الذي يلي النطاق مباشرةً في الحالات الأخرى.
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();
الإرجاع
Integer
: هو مؤشر مفتاح التحكّم في هذه المجموعة.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDepth()
تعرض هذه السمة عمق هذه المجموعة.
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();
الإرجاع
Integer
: عمق هذه المجموعة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange()
تعرِض النطاق الذي توجد فيه هذه المجموعة.
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();
الإرجاع
Range
: النطاق الذي توجد فيه المجموعة.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isCollapsed()
تعرِض هذه السمة القيمة true
إذا كانت هذه المجموعة مصغّرة.
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();
الإرجاع
Boolean
— true
إذا كانت هذه المجموعة مصغّرة، تعرض false
بخلاف ذلك.
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove()
تؤدي هذه السمة إلى إزالة هذه المجموعة من الورقة، ما يؤدي إلى تقليل عمق المجموعة في range
بمقدار واحد. قد يؤدي ذلك إلى تعديل مجموعات أخرى. بعد استدعاء هذا الإجراء، يصبح عنصر المجموعة غير صالح للاستخدام.
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();
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
انظر أيضًا
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-13 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-13 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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))"]]