Range class

Range class

Represents a contiguous area in a document. To learn more, visit the Working with Ranges documentation article.

Remarks

The document is represented by a tree of nodes and the nodes provide operations to work with the tree, but some operations are easier to perform if the document is treated as a contiguous sequence of text.

Range is a “facade” interface that provide methods that treat the document or portions of the document as “flat” text regardless of the fact that the document nodes are stored in a tree-like object model.

Range does not contain any text or nodes, it is merely a view or “window” over a fragment of a document.

Properties

NameDescription
bookmarksReturns a Range.bookmarks collection that represents all bookmarks in the range.
fieldsReturns a Range.fields collection that represents all fields in the range.
form_fieldsReturns a Range.form_fields collection that represents all form fields in the range.
revisionsGets a collection of revisions (tracked changes) that exist in this range.
structured_document_tagsReturns a Range.structured_document_tags collection that represents all structured document tags in the range.
textGets the text of the range.

Methods

NameDescription
delete()Deletes all characters of the range.
normalize_field_types()Changes field type values FieldChar.field_type of FieldStart, FieldSeparator, FieldEnd in this range so that they correspond to the field types contained in the field codes.
replace(pattern, replacement)Replaces all occurrences of a specified character string pattern with a replacement string.
replace(pattern, replacement, options)Replaces all occurrences of a specified character string pattern with a replacement string.
replace_regex(pattern, replacement)Replaces all occurrences of a character pattern specified by a regular expression with another string.
replace_regex(pattern, replacement, options)Replaces all occurrences of a character pattern specified by a regular expression with another string.
to_document()Constructs a new fully formed document that contains the range.
unlink_fields()Unlinks fields in this range.
update_fields()Updates the values of document fields in this range.

Examples

Shows how to get the text contents of all the nodes that a range covers.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.write('Hello world!')
self.assertEqual('Hello world!', doc.range.text.strip())

See Also