public class Range
extends java.lang.Object
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.
| Modifier and Type | Method and Description |
|---|---|
void |
delete()
Deletes all characters of the range.
|
BookmarkCollection |
getBookmarks()
Returns a
getBookmarks() collection that represents all bookmarks in the range. |
FieldCollection |
getFields()
Returns a
getFields() collection that represents all fields in the range. |
FormFieldCollection |
getFormFields()
Returns a
getFormFields() collection that represents all form fields in the range. |
StructuredDocumentTagCollection |
getStructuredDocumentTags()
Returns a
getStructuredDocumentTags() collection that represents all structured document tags in the range. |
java.lang.String |
getText()
Gets the text of the range.
|
void |
normalizeFieldTypes()
Changes field type values
FieldChar.getFieldType() of FieldStart, FieldSeparator, FieldEnd in this range so that they correspond to the field types contained in the field codes. |
int |
replace(java.util.regex.Pattern pattern,
java.lang.String replacement)
Replaces all occurrences of a character pattern specified by a regular expression with another string.
|
int |
replace(java.util.regex.Pattern pattern,
java.lang.String replacement,
FindReplaceOptions options)
Replaces all occurrences of a character pattern specified by a regular expression with another string.
|
int |
replace(java.lang.String pattern,
java.lang.String replacement)
Replaces all occurrences of a specified character string pattern with a replacement string.
|
int |
replace(java.lang.String pattern,
java.lang.String replacement,
FindReplaceOptions options)
Replaces all occurrences of a specified character string pattern with a replacement string.
|
Document |
toDocument()
Constructs a new fully formed document that contains the range.
|
void |
unlinkFields()
Unlinks fields in this range.
|
void |
updateFields()
Updates the values of document fields in this range.
|
public java.lang.String getText()
The returned string includes all control and special characters as described in ControlChar.
public FormFieldCollection getFormFields()
getFormFields() collection that represents all form fields in the range.getFormFields() collection that represents all form fields in the range.public BookmarkCollection getBookmarks()
getBookmarks() collection that represents all bookmarks in the range.getBookmarks() collection that represents all bookmarks in the range.public FieldCollection getFields()
getFields() collection that represents all fields in the range.getFields() collection that represents all fields in the range.public StructuredDocumentTagCollection getStructuredDocumentTags()
getStructuredDocumentTags() collection that represents all structured document tags in the range.getStructuredDocumentTags() collection that represents all structured document tags in the range.public void delete()
public int replace(java.lang.String pattern,
java.lang.String replacement)
throws java.lang.Exception
The pattern will not be used as regular expression. Please use replace(java.util.regex.Pattern, java.lang.String) if you need regular expressions.
Used case-insensitive comparison.
Method is able to process breaks in both pattern and replacement strings.
You should use special meta-characters if you need to work with breaks:replace(java.lang.String, java.lang.String, com.aspose.words.FindReplaceOptions) to have more flexible customization.pattern - A string to be replaced.replacement - A string to replace all occurrences of pattern.java.lang.Exceptionpublic int replace(java.util.regex.Pattern pattern,
java.lang.String replacement)
throws java.lang.Exception
Replaces the whole match captured by the regular expression.
Method is able to process breaks in both pattern and replacement strings.
You should use special meta-characters if you need to work with breaks:replace(java.util.regex.Pattern, java.lang.String, com.aspose.words.FindReplaceOptions) to have more flexible customization.pattern - A regular expression pattern used to find matches.replacement - A string to replace all occurrences of pattern.java.lang.Exceptionpublic int replace(java.lang.String pattern,
java.lang.String replacement,
FindReplaceOptions options)
throws java.lang.Exception
The pattern will not be used as regular expression. Please use replace(java.util.regex.Pattern, java.lang.String, com.aspose.words.FindReplaceOptions) if you need regular expressions.
Method is able to process breaks in both pattern and replacement strings.
You should use special meta-characters if you need to work with breaks:pattern - A string to be replaced.replacement - A string to replace all occurrences of pattern.options - FindReplaceOptions object to specify additional options.java.lang.Exceptionpublic int replace(java.util.regex.Pattern pattern,
java.lang.String replacement,
FindReplaceOptions options)
throws java.lang.Exception
Replaces the whole match captured by the regular expression.
Method is able to process breaks in both pattern and replacement strings.
You should use special meta-characters if you need to work with breaks:pattern - A regular expression pattern used to find matches.replacement - A string to replace all occurrences of pattern.options - FindReplaceOptions object to specify additional options.java.lang.Exceptionpublic void updateFields()
throws java.lang.Exception
When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.
There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.
This method does not update all field types. For the detailed list of supported field types, see the Programmers Guide.
This method does not update fields that are related to the page layout algorithms (e.g. PAGE, PAGES, PAGEREF). The page layout-related fields are updated when you render a document or call Document.updatePageLayout().
To update fields in the whole document use Document.updateFields().
java.lang.Exceptionpublic void unlinkFields()
throws java.lang.Exception
Replaces all the fields in this range with their most recent results.
To unlink fields in the whole document use unlinkFields().
java.lang.Exceptionpublic void normalizeFieldTypes()
FieldChar.getFieldType() of FieldStart, FieldSeparator, FieldEnd in this range so that they correspond to the field types contained in the field codes.
Use this method after document changes that affect field types.
To change field type values in the whole document use Document.normalizeFieldTypes().
public Document toDocument() throws java.lang.Exception
java.lang.Exception