This topic describes API operations that are related to Range objects in documents.
Range
ActiveDocument.Range(Start, End)
Returns a Range object. Each Range object is defined by a starting and ending character position.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Range(Start, End)Or,
expression.ActiveDocument.ActiveWindow.Selection.RangeOr,
expression.ActiveDocument.Tables.Item(Index).RangeOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Rangeexpression: an Application object
Examples
Return a Range object in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); }Return a Range object from a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; }
Methods
ActiveDocument.Range().Item()
Returns a Range object within the specified Range object.
Syntax
expression.ActiveDocument.Range(Start, End).Item({ Start, End })Or,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Item({ Start, End })expression: an Application object
Parameters
Parameter
Data type
Required
Description
Start
Number
Yes
The start position.
End
Number
Yes
The end position.
Examples
Return a Range object from the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return another Range object within the Range object. const item = await range.Item(0, 50); }Return a Range object from a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return another Range object within the Range object. const item = await range.Item(1, 10); }
ActiveDocument.Range(Start, End).GetHtmlData()
Returns formatted HTML data in a Range object.
Only JS-SDK V1.1.14 and later support this feature.
Syntax
expression.ActiveDocument.Range(Start, End).GetHtmlData()expression: an Application object
Return values
Parameter
Data type
Description
HTML
String
HTML data.
Text
String
Text data.
Example
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(10, 20); // Return the formatted HTML data in the Range object. const htmlInfo = await range.GetHtmlData(); console.log(htmlInfo); }
ActiveDocument.Range(Start, End).PasteHtml()
Pastes formatted HTML data into a Range object.
Only JS-SDK V1.1.14 and later support this feature.
Syntax
expression.ActiveDocument.Range(Start, End).PasteHtml({ HTML })expression: an Application object
Parameters
Parameter
Data type
Required
Description
HTML
String
Yes
The HTML data. You can call the
ActiveDocument.Range(Start, End).GetHtmlData()method to return HTML data.Example
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(10, 20); // Return the formatted HTML data in the Range object. const htmlInfo = await range.GetHtmlData(); // Paste the formatted HTML data into a Range object. await app.ActiveDocument.Range(110, 110).PasteHtml({ HTML: htmlInfo.HTML, }); }
ActiveDocument.Range(Start, End).SetRange()
Sets the starting and ending character positions for an existing Range object.
Syntax
expression.ActiveDocument.Range(Start, End).SetRange({ Start, End })Or,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.SetRange({ Start, End })expression: an Application object
Parameters
Parameter
Data type
Required
Description
Start
Number
Yes
The starting character position.
End
Number
Yes
The ending character position.
Examples
Set the starting and ending character positions for an existing Range object in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Set the starting and ending character positions for the Range object. await range.SetRange(10, 20); }Set the starting and ending character positions for an existing range in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Set the starting and ending character positions for the Range object. const newRange = await range.SetRange({ Start: 1, End: 10, }); }
ActiveDocument.Range(Start, End).Find
Searches for specific information in a range.
Only JS-SDK V1.1.19 and later support this feature.
Syntax
expression.ActiveDocument.Range(Start, End).Findexpression: an Application object
Parameters
Parameter
Data type
Default value
Required
Description
Text
String
Yes
The information to search for.
ShowHighlight
Boolean
true
No
Specifies whether to highlight the information.
FilterConfig
Object
true
No
The configuration items (supported by WebOffice V8.5.1+)
FilterConfig
Element
Data type
Default value
Required
Description
isCaseSensitive
Boolean
false
No
Specifies whether to apply case sensitivity.
isWholeWordMatched
Boolean
false
No
Specifies whether to use whole-word matching.
isWidthIgnored
Boolean
false
No
Specifies whether to ignore character width (full-width and half-width).
isWildcardMatched
Boolean
false
No
Specifies whether to use wildcard characters.
isRegexMatched
Boolean
false
No
Specifies whether to apply regular expressions. Regular expressions take precedence over wildcard characters if both are applied to the search.
Example
async function example() { await instance.ready(); const app = instance.Application; // Return the specified Range object. const range = await app.ActiveDocument.Range(0, 10); // Search for the information. range.Find('WPS') }
Properties
ActiveDocument.Range(Start, End).Start
Returns the start position of a Range object.
Syntax
expression.ActiveDocument.Range(Start, End).StartOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Startexpression: an Application object
Examples
Return the starting character position of a Range object in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return the start position of the Range object. const start = await range.Start; console.log(start); }Return the start position of a Range object in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return the start position of the Range object. const start = await range.Start; console.log(start); }
ActiveDocument.Range(Start, End).End
Returns the end position of a range.
Syntax
expression.ActiveDocument.Range(Start, End).EndOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Endexpression: an Application object
Examples
Return the end position of a Range object in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return the end position of the Range object. const end = await range.End; console.log(end); }Return the end position of a range in a cell.
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return the end position of the Range object. const end = await range.End; console.log(end); }
ActiveDocument.Range(Start, End).Font
Returns a Font object that represents the font of a range.
Syntax
expression.ActiveDocument.Range(Start, End).FontOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Fontexpression: an Application object
Examples
Return the Font object of a range in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return the Font object. const font = await range.Font; console.log(font); }Return the Font object of a range in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return the Font object. const font = await range.Font; }
ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndex
Sets or returns the highlight color for a range. The highlight color remains after a page refresh.
Syntax
expression.ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndex=WdColorIndexexpression: an Application object
Parameters
Parameter
Data type
Required
Description
WdColorIndex
Enum
No
Specifies the highlight color of the specified range. For more information, see WdColorIndex.
Example
async function example() { await instance.ready(); const app = instance.Application; // Set or return the highlight color for the specified range. The highlight color remains after a page refresh. app.ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndex = 7; }
ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndexTemp
Sets or returns the highlight color of a range. The highlight color disappears after a page refresh.
Syntax
expression.ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndexTemp=WdColorIndexexpression: an Application object
Parameters
Parameter
Data type
Required
Description
WdColorIndex
Enum
No
The highlight color of the specified range. For more information, see WdColorIndex.
Example
async function example() { await instance.ready(); const app = instance.Application; // Set or return the highlight color of the specified range. The highlight color disappears after a page refresh. app.ActiveDocument.ActiveWindow.Selection.Range.HighlightColorIndexTemp = 7; }
ActiveDocument.Range.Information()
Returns page information. Only the total number of pages is available.
Only JS-SDK V1.1.10 and later support this feature.
Liquid layout design is applied to documents. Therefore, the total number of pages in a document is available only when the document is browsed to its last page.
Syntax
expression.ActiveDocument.Range.Information(WdInformation)expression: an Application object
Parameters
The following table describes the types of information about the selection or range that you can obtain by using
app.Enum.WdInformation.Parameter
Data type
Required
Description
WdInformation
Enum
Yes
The page information. Only the total number of pages is available. For more information, see WdInformation.
Return values
Parameter
Data type
Description
PagesCount
Number
The number of pages for which typesetting is complete.
End
Boolean
Indicates whether the typesetting ends.
Example
async function example() { await instance.ready(); const app = instance.Application; // Return the total number of pages. const totalPages = await app.ActiveDocument.Range.Information(app.Enum.WdInformation.wdNumberOfPagesInDocument); console.log(totalPages); }
ActiveDocument.Range(Start, End).Paragraphs
Returns all the paragraphs in a range.
Only JS-SDK V1.1.14 and later support this feature.
Syntax
expression.ActiveDocument.Range(Start, End).ParagraphsOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Paragraphsexpression: an Application object
Examples
Return all the paragraphs in a range in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return all the paragraphs in the Range object. const info = await range.Paragraphs; }Return all the paragraphs in a Range object in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return all the paragraphs in the Range object. const paragraphFormat = await range.Paragraphs; }
ActiveDocument.Range(Start, End).ParagraphFormat
Returns paragraph format settings of a range.
Syntax
expression.ActiveDocument.Range(Start, End).ParagraphFormatOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.ParagraphFormatexpression: an Application object
Examples
Return paragraph format settings of a range in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return paragraph format settings of the Range object. const info = await range.ParagraphFormat; }Return paragraph format settings of a range in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return paragraph format settings of the Range object. const paragraphFormat = await range.ParagraphFormat; }
ActiveDocument.Range(Start, End).Text
Sets and queries the text for a range.
JS-SDK V1.1.10 and later support text query.
JS-SDK V1.1.11 and later support text setting.
Syntax
expression.ActiveDocument.Range(Start, End).TextOr,
expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range.Textexpression: an Application object
Examples
Set and query the text for a range in the active document
async function example() { await instance.ready(); const app = instance.Application; // Return a Range object. const range = app.ActiveDocument.Range(0, 100); // Return the text. const text = await range.Text; console.log(text); // Set the text. range.Text = 'Aliyun'; }Set and query the text for a range in a cell
async function example() { await instance.ready(); const app = instance.Application; // Return the first table. const tableOne = await app.ActiveDocument.Tables.Item(1); // Return the first cell in the first row of the table. const cellOne = await tableOne.Rows.Item(1).Cells.Item(1); // Return a Range object from the cell. const range = await cellOne.Range; // Return the text. const text = await range.Text; console.log(text); // Set the text. range.Text = 'Aliyun'; }