Class NamedRange

NamedRange

A Range that has a name and ID to allow later retrieval. Names are not necessarily unique; several different ranges in the same document may share the same name, much like a class in HTML. By contrast, IDs are unique within the document, like an ID in HTML. Once a NamedRange has been added to a document, it cannot be modified, only removed.

A NamedRange can be accessed by any script that accesses the document. To avoid unintended conflicts between scripts, consider prefixing range names with a unique string.


 // Create a named range that includes every table in the document.
 var doc = DocumentApp.getActiveDocument();
 var rangeBuilder = doc.newRange();
 var tables = doc.getBody().getTables();
 for (var i = 0; i < tables.length; i++) {
   rangeBuilder.addElement(tables[i]);
 }
 doc.addNamedRange('myUniquePrefix-tables', rangeBuilder.build());
 

Methods

MethodReturn typeBrief description
getId()StringGets the ID of this NamedRange.
getName()StringGets the name of this NamedRange.
getRange()RangeGets the range of elements associated with this NamedRange.
remove()voidRemoves this NamedRange from the document.

Detailed documentation

getId()

Gets the ID of this NamedRange. The ID is unique within the document.

Return

String — the range's ID, which is unique within the document


getName()

Gets the name of this NamedRange. The name is not necessarily unique.

Return

String — the range's name, which is not necessarily unique


getRange()

Gets the range of elements associated with this NamedRange.

Return

Range — the range of elements associated with the name and ID


remove()

Removes this NamedRange from the document. This method does not delete the contents of the range; it merely the removes the reference. Calling this method on a NamedRange that has already been removed has no effect.

发送以下问题的反馈:

此网页
Apps Script
Apps Script