تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
النطاق
نطاق من العناصر في مستند يتم تمثيل اختيار المستخدم على أنّه Range، من بين استخدامات أخرى. لا يمكن للنصوص البرمجية الوصول إلا إلى اختيار المستخدم الذي يشغّل النص البرمجي، وفقط إذا كان النص البرمجي مرتبطًا بالمستند.
// Bold all selected text.constselection=DocumentApp.getActiveDocument().getSelection();if(selection){constelements=selection.getRangeElements();for(leti=0;i < elements.length;i++){constelement=elements[i];// Only modify elements that can be edited as text; skip images and other// non-text elements.if(element.getElement().editAsText){consttext=element.getElement().editAsText();// Bold the selected part of the element, or the full element if it's// completely selected.if(element.isPartial()){text.setBold(element.getStartOffset(),element.getEndOffsetInclusive(),true,);}else{text.setBold(true);}}}}
تحصل على جميع العناصر التي اختارها المستخدم في النسخة المفتوحة من المستند، بما في ذلك أي Text عناصر تم اختيارها جزئيًا.
مستندات تفصيلية
getRangeElements()
تحصل على جميع العناصر في هذا Range، بما في ذلك أي عناصر Text جزئية (على سبيل المثال، في حال اختيار يتضمّن جزءًا فقط من عنصر Text). لتحديد ما إذا كان عنصر Text مضمّنًا جزئيًا فقط في النطاق، اطّلِع على RangeElement.isPartial().
الإرجاع
RangeElement[]: صفيف من العناصر بترتيب ظهورها في المستند
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eA \u003ccode\u003eRange\u003c/code\u003e represents a range of elements in a Google Doc, often used to represent the user's selection.\u003c/p\u003e\n"],["\u003cp\u003eScripts can only access the selection of the user who is running them within the bound document.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetRangeElements()\u003c/code\u003e method retrieves all elements within the range, including partially selected text elements.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetSelectedElements()\u003c/code\u003e method is deprecated and has been replaced by \u003ccode\u003egetRangeElements()\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Range\n\nA range of elements in a document. The user's selection is represented as a `Range`, among\nother uses. Scripts can only access the selection of the user who is running the script, and only\nif the script is [bound](/apps-script/scripts_containers) to the document.\n\n```javascript\n// Bold all selected text.\nconst selection = DocumentApp.getActiveDocument().getSelection();\nif (selection) {\n const elements = selection.getRangeElements();\n for (let i = 0; i \u003c elements.length; i++) {\n const element = elements[i];\n\n // Only modify elements that can be edited as text; skip images and other\n // non-text elements.\n if (element.getElement().editAsText) {\n const text = element.getElement().editAsText();\n\n // Bold the selected part of the element, or the full element if it's\n // completely selected.\n if (element.isPartial()) {\n text.setBold(\n element.getStartOffset(),\n element.getEndOffsetInclusive(),\n true,\n );\n } else {\n text.setBold(true);\n }\n }\n }\n}\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-------------------------------------------|-----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getRangeElements()](#getRangeElements()) | [RangeElement[]](/apps-script/reference/document/range-element) | Gets all elements in this `Range`, including any partial [Text](/apps-script/reference/document/text) elements (for example, in the case of a selection that includes only part of a `Text` element). |\n\nDeprecated methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------|-----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getSelectedElements()](#getSelectedElements()) | [RangeElement[]](/apps-script/reference/document/range-element) | Gets all elements that the user has selected in the open instance of the document, including any partially selected [Text](/apps-script/reference/document/text) elements. |\n\nDetailed documentation \n\n`get``Range``Elements()` \nGets all elements in this `Range`, including any partial [Text](/apps-script/reference/document/text) elements (for example, in the case\nof a selection that includes only part of a `Text` element). To determine whether a\n`Text` element is only partially included in the range, see [RangeElement.isPartial()](/apps-script/reference/document/range-element#isPartial()).\n\nReturn\n\n\n[RangeElement[]](/apps-script/reference/document/range-element) --- an array of elements, in the order they appear in the document\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\nDeprecated methods \n\n`get``Selected``Elements()` \n\n**Deprecated.** Renamed to [getRangeElements()](#getRangeElements()).\n\nGets all elements that the user has selected in the open instance of the document, including\nany partially selected [Text](/apps-script/reference/document/text)\nelements.\n\nReturn\n\n\n[RangeElement[]](/apps-script/reference/document/range-element) --- an array of selected or partially selected elements, in the order they appear in the\ndocument\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`"]]