Stay organized with collections Save and categorize content based on your preferences.
RangeA range of elements in a document. The user's selection is represented as a Range
, among other uses. Scripts can only access the selection of the user who is running the script, and only if the script is bound to the document.
// Bold all selected text. const selection = DocumentApp.getActiveDocument().getSelection(); if (selection) { const elements = selection.getRangeElements(); for (let i = 0; i < elements.length; i++) { const element = elements[i]; // Only modify elements that can be edited as text; skip images and other // non-text elements. if (element.getElement().editAsText) { const text = 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); } } } }Methods Method Return type Brief description
getRangeElements()
RangeElement[]
Gets all elements in this Range
, including any partial Text
elements (for example, in the case of a selection that includes only part of a Text
element). Deprecated methods Method Return type Brief description getSelectedElements()
RangeElement[]
Gets all elements that the user has selected in the open instance of the document, including any partially selected Text
elements. Detailed documentation getRangeElements()
Gets all elements in this Range
, including any partial Text
elements (for example, in the case of a selection that includes only part of a Text
element). To determine whether a Text
element is only partially included in the range, see RangeElement.isPartial()
.
RangeElement[]
— an array of elements, in the order they appear in the document
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getSelectedElements()
Deprecated. Renamed to getRangeElements()
.
Gets all elements that the user has selected in the open instance of the document, including any partially selected Text
elements.
RangeElement[]
— an array of selected or partially selected elements, in the order they appear in the document
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["A `Range` represents a range of elements in a Google Doc, often used to represent the user's selection."],["Scripts can only access the selection of the user who is running them within the bound document."],["The `getRangeElements()` method retrieves all elements within the range, including partially selected text elements."],["The `getSelectedElements()` method is deprecated and has been replaced by `getRangeElements()`."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4