Class RangeBuilder

Range Builder

A builder used to construct Range objects from document elements.

 // Change the user's selection to a range that includes every table in the 
 // active tab. 
 const 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 const 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 (). 
 asDocumentTab 
 (); 
 const 
  
 rangeBuilder 
  
 = 
  
 documentTab 
 . 
 newRange 
 (); 
 const 
  
 tables 
  
 = 
  
 documentTab 
 . 
 getBody 
 (). 
 getTables 
 (); 
 for 
  
 ( 
 let 
  
 i 
  
 = 
  
 0 
 ; 
  
 i 
 < 
 tables 
 . 
 length 
 ; 
  
 i 
 ++ 
 ) 
  
 { 
  
 rangeBuilder 
 . 
 addElement 
 ( 
 tables 
 [ 
 i 
 ]); 
 } 
 doc 
 . 
 setSelection 
 ( 
 rangeBuilder 
 . 
 build 
 ()); 

Methods

Method Return type Brief description
Range Builder Adds an entire Element to this Range Builder .
Range Builder Adds a partial Text element to this Range Builder .
Range Builder Adds two entire elements, and all elements between them, to this Range Builder .
Range Builder Adds two partial Text elements, and all elements between them, to the Range Builder .
Range Builder Adds the contents of another Range to this Range Builder .
Range Constructs a Range from the settings applied to the builder.
Range Element[] 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).

Detailed documentation

add Element(element)

Adds an entire Element to this Range Builder .

Parameters

Name Type Description
element
Element the element to be added

Return

Range Builder — this builder, for chaining

Authorization

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

add Element(textElement, startOffset, endOffsetInclusive)

Adds a partial Text element to this Range Builder .

Parameters

Name Type Description
text Element
Text the text element to be partially added
start Offset
Integer the number of characters before the first character to be included (that is, the index of the first character in the range)
end Offset Inclusive
Integer the number of characters before the last character to be included (that is, the index of the last character in the range)

Return

Range Builder — this builder, for chaining

Authorization

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

add Elements Between(startElement, endElementInclusive)

Adds two entire elements, and all elements between them, to this Range Builder .

Parameters

Name Type Description
start Element
Element the first element to be added
end Element Inclusive
Element the last element to be added

Return

Range Builder — this builder, for chaining

Authorization

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

add Elements Between(startTextElement, startOffset, endTextElementInclusive, endOffsetInclusive)

Adds two partial Text elements, and all elements between them, to the Range Builder .

Parameters

Name Type Description
start Text Element
Text the first text element to be partially added
start Offset
Integer the number of characters before the first character of start Text Element to be included (that is, the index of the first character in the range)
end Text Element Inclusive
Text the last text element to be partially added
end Offset Inclusive
Integer the number of characters before the last character of end Text Element Inclusive to be included (that is, the index of the last character in the range)

Return

Range Builder — this builder, for chaining

Authorization

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

add Range(range)

Adds the contents of another Range to this Range Builder .

Parameters

Name Type Description
range
Range the range whose elements should be added

Return

Range Builder — this builder, for chaining

Authorization

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

build()

Constructs a Range from the settings applied to the builder.

Return

Range — the newly constructed range


get Range Elements()

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 Range Element.isPartial() .

Return

Range Element[] — an array of elements, in the order they appear in the document

Authorization

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

Deprecated methods

Create a Mobile Website
View Site in Mobile | Classic
Share by: