Get Started
Usage API
More information

ApiRange

new ApiRange(Start, End)

Class represents a continuous region in a document. Each Range object is determined by the position of the start and end characters.

Parameters:

Name Type Description
Start Number

The start element of Range in the current Element.

End Number

The end element of Range in the current Element.

Methods

Name Description
AddBookmark

Add the bookmark to the specified range.

AddHyperlink

Add a hyperlink to the specified range.

AddText

Add text to the specified position.

Delete

Delete all the contents from the current range.

ExpandTo

Return a new range that goes beyond the specified range in any direction and spans a different range. The current range has not changed. Throws an error if two ranges do not have a union.

GetAllParagraphs

Get a collection of paragraphs that represents all the paragraphs in the specified range.

GetClassType

Get the type of this class.

GetParagraph

Get a paragraph from all the paragraphs that are in the range.

GetText

Get text from the specified range.

IntersectWith

Return a new range as the intersection of this range with another range. The current range has not changed. Throws an error if two ranges do not overlap or are not adjacent.

Select

Set the selection to the specified range.

SetBold

Set the bold property to the text character.

SetCaps

Specify that any lowercase characters in this text Range are formatted for display only as their capital letter character equivalents.

SetColor

Set the text color for the current text Range in the RGB format.

SetDoubleStrikeout

Specify that the contents of this Range are displayed with two horizontal lines through each character displayed on the line.

SetFontFamily

Set all 4 font slots with the specified font family.

SetFontSize

Set the font size for the characters of the current text Range.

SetHighlight

Specify a highlighting color in the RGB format which is applied as a background for the contents of the current Range.

SetItalic

Set the italic property to the text character.

SetPosition

Specify the amount by which text is raised or lowered for this Range in relation to the default baseline of the surrounding non-positioned text.

SetShd

Specify the shading applied to the contents of the current text Range.

SetSmallCaps

Specify that all the small letter characters in this text Range are formatted for display only as their capital letter character equivalents which are two points smaller than the actual font size specified for this text.

SetSpacing

Set text spacing measured in twentieths of a point.

SetStrikeout

Specify that the contents of this Range are displayed with a single horizontal line through the range center.

SetStyle

Set the style for the current Range.

SetTextPr

Set the text properties for the current Range.

SetUnderline

Specify that the contents of this Range are displayed along with a line appearing directly below the character (less than all the spacing above and below the characters on the line).

SetVertAlign

Specify the alignment which will be applied to the Range contents in relation to the default appearance of the Range text:

  • "baseline" - the characters in the current text Range will be aligned by the default text baseline.
  • "subscript" - the characters in the current text Range will be aligned below the default text baseline.
  • "superscript" - the characters in the current text Range will be aligned above the default text baseline.

Example

Copy code
builder.CreateFile("docx");
oDocument = Api.GetDocument();
oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is just a sample text to demonstrate the methods for ApiRange. ");
oParagraph.GetRange(57, 64).AddBookmark("class ApiRange");
oParagraph.GetRange(57, 66).AddText("onlyoffice", "after");
oParagraph.GetRange(67, 76).AddHyperlink("https://api.onlyoffice.com/docbuilder/basic");
oParagraph.GetRange(67, 76).SetCaps(true);
oParagraph.GetRange(67, 76).SetSpacing(2);
oParagraph.GetRange(0, 3).SetColor(255, 164, 101);
oParagraph.GetRange(30, 40).SetFontFamily("Comic Sans MS");
oParagraph.GetRange(5, 6).SetFontSize(16);
oParagraph.GetRange(57, 65).SetBold(true);
oParagraph.GetRange(15, 20).SetDoubleStrikeout(true);
oParagraph.GetRange(13, 13).SetItalic(true);
oParagraph.GetRange(22, 25).SetUnderline(true);
oParagraph.GetRange(27, 28).SetSmallCaps(true);
oParagraph.GetRange(46, 52).SetShd("clear", 255, 224, 204);
oParagraph.GetRange(42, 44).SetStrikeout(true);
oParagraph.GetRange(7, 11).Delete();
builder.SaveFile("docx", "ApiRange.docx");
builder.CloseFile();

Resulting document