Class RangeElement
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
IntervalloElemento
Un wrapper per un Element
con un possibile offset di inizio e di fine. Questi offset consentono di rappresentare un intervallo di caratteri all'interno di un elemento Text
nei risultati di ricerca, nelle selezioni di documenti e negli intervalli denominati.
Metodi
Metodo | Tipo restituito | Breve descrizione |
getElement() | Element | Recupera il Element corrispondente a questo RangeElement . |
getEndOffsetInclusive() | Integer | Recupera la posizione della fine di un intervallo parziale all'interno dell'elemento intervallo. |
getStartOffset() | Integer | Recupera la posizione dell'inizio di un intervallo parziale all'interno dell'elemento intervallo. |
isPartial() | Boolean | Determina se questo elemento intervallo copre l'intero elemento o una selezione parziale dei caratteri dell'elemento. |
Documentazione dettagliata
getElement()
Recupera il Element
corrispondente a questo RangeElement
.
const rangeElement = DocumentApp.getActiveDocument().getSelection().getRangeElements()[0];
// Log debug information about a range element.
Logger.log(`Element type: ${rangeElement.getElement().getType()}`);
if (rangeElement.isPartial()) {
Logger.log(`The character range begins at ${rangeElement.getStartOffset()}`);
Logger.log(
`The character range ends at ${rangeElement.getEndOffsetInclusive()}`,
);
} else {
Logger.log('The entire range element is included.');
}
Invio
Element
: l'elemento che corrisponde a questo RangeElement
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getEndOffsetInclusive()
Recupera la posizione della fine di un intervallo parziale all'interno dell'elemento intervallo. Se l'elemento è un elemento Text
e isPartial()
restituisce true
, l'offset è il numero di caratteri prima dell'ultimo carattere nell'intervallo (ovvero l'indice dell'ultimo carattere nell'intervallo); in ogni altro caso, questo metodo restituisce -1
.
Invio
Integer
: per gli elementi Text
, il numero di caratteri prima dell'ultimo carattere dell'intervallo; per gli altri elementi, -1
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getStartOffset()
Recupera la posizione dell'inizio di un intervallo parziale all'interno dell'elemento intervallo. Se l'elemento è un elemento Text
e isPartial()
restituisce true
, l'offset è il numero di caratteri prima dell'inizio dell'intervallo (ovvero l'indice del primo carattere nell'intervallo); in ogni altro caso, questo metodo restituisce -1
.
Invio
Integer
: per gli elementi Text
, il numero di caratteri prima dell'inizio dell'intervallo; per gli altri elementi, -1
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isPartial()
Determina se questo elemento intervallo copre l'intero elemento o una selezione parziale dei caratteri dell'elemento. L'inizio e la fine dell'intervallo di un elemento di intervallo parziale possono essere
determinati utilizzando rispettivamente getStartOffset()
e getEndOffsetInclusive()
.
Invio
Boolean
- true
se l'elemento è incluso parzialmente; false
in caso contrario
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eRangeElement\u003c/code\u003e is a wrapper around an \u003ccode\u003eElement\u003c/code\u003e that can represent a range of characters within a \u003ccode\u003eText\u003c/code\u003e element.\u003c/p\u003e\n"],["\u003cp\u003eIt is used in search results, document selections, and named ranges, allowing for partial or full element selection.\u003c/p\u003e\n"],["\u003cp\u003eYou can get the corresponding \u003ccode\u003eElement\u003c/code\u003e, determine if the range is partial, and find the start and end positions of partial ranges using its methods.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eRangeElement\u003c/code\u003e methods require authorization with specific scopes, like \u003ccode\u003ehttps://www.googleapis.com/auth/documents\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Class RangeElement\n\nRangeElement\n\nA wrapper around an [Element](/apps-script/reference/document/element) with a possible start and end offset. These offsets allow a\nrange of characters within a [Text](/apps-script/reference/document/text)\nelement to be represented in search results, document selections, and named ranges. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------|----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|\n| [getElement()](#getElement()) | [Element](/apps-script/reference/document/element) | Gets the [Element](/apps-script/reference/document/element) that corresponds to this `Range``Element`. |\n| [getEndOffsetInclusive()](#getEndOffsetInclusive()) | `Integer` | Gets the position of the end of a partial range within the range element. |\n| [getStartOffset()](#getStartOffset()) | `Integer` | Gets the position of the start of a partial range within the range element. |\n| [isPartial()](#isPartial()) | `Boolean` | Determines whether this range element covers the entire element or a partial selection of the element's characters. |\n\nDetailed documentation\n----------------------\n\n### `get``Element()`\n\nGets the [Element](/apps-script/reference/document/element) that corresponds to this `Range``Element`.\n\n```javascript\nconst rangeElement = DocumentApp.getActiveDocument().getSelection().getRangeElements()[0];\n\n// Log debug information about a range element.\nLogger.log(`Element type: ${rangeElement.getElement().getType()}`);\nif (rangeElement.isPartial()) {\n Logger.log(`The character range begins at ${rangeElement.getStartOffset()}`);\n Logger.log(\n `The character range ends at ${rangeElement.getEndOffsetInclusive()}`,\n );\n} else {\n Logger.log('The entire range element is included.');\n}\n```\n\n#### Return\n\n\n[Element](/apps-script/reference/document/element) --- the element that corresponds to this `Range``Element`\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``End``Offset``Inclusive()`\n\nGets the position of the end of a partial range within the range element. If the element is a\n[Text](/apps-script/reference/document/text) element and [isPartial()](#isPartial()) returns `true`, the offset is the number of characters before the last\ncharacter in the range (that is, the index of the last character in the range); in any other\ncase, this method returns `-1`.\n\n#### Return\n\n\n`Integer` --- for [Text](/apps-script/reference/document/text) elements, the\nnumber of character before the last character in the range; for other elements, `-1`\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Start``Offset()`\n\nGets the position of the start of a partial range within the range element. If the element is a\n[Text](/apps-script/reference/document/text) element and [isPartial()](#isPartial()) returns `true`, the offset is the number of characters before the start of\nthe range (that is, the index of the first character in the range); in any other case, this\nmethod returns `-1`.\n\n#### Return\n\n\n`Integer` --- for [Text](/apps-script/reference/document/text) elements, the\nnumber of characters before the start of the range; for other elements, `-1`\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `is``Partial()`\n\nDetermines whether this range element covers the entire element or a partial selection of the\nelement's characters. The beginning and end of a partial range element's range can be\ndetermined using [getStartOffset()](#getStartOffset()) and [getEndOffsetInclusive()](#getEndOffsetInclusive()), respectively.\n\n#### Return\n\n\n`Boolean` --- `true` if the element is partially included; `false` if not\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/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`"]]