ApiRange

new ApiRange(Start, End)

Class representing 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

Adds a bookmark to the specified range.

AddComment

Adds a comment to the current range.

AddHyperlink

Adds a hyperlink to the specified range.

AddText

Adds a text to the specified position.

Delete

Deletes all the contents from the current range.

ExpandTo

Returns 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

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

GetClassType

Returns a type of the ApiRange class.

GetParagraph

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

GetRange

Returns a Range object that represents the document part contained in the specified range.

GetText

Returns a text from the specified range.

IntersectWith

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

Select

Sets the selection to the specified range.

SetBold

Sets the bold property to the text character.

SetCaps

Specifies that any lowercase characters in the current text Range are formatted for display only as their capital letter character equivalents.

SetColor

Sets the text color to the current text Range in the RGB format.

SetDoubleStrikeout

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

SetFontFamily

Sets all 4 font slots with the specified font family.

SetFontSize

Sets the font size to the characters of the current text Range.

SetHighlight

Specifies a highlighting color which is applied as a background to the contents of the current Range.

SetItalic

Sets the italic property to the text character.

SetPosition

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

SetShd

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

SetSmallCaps

Specifies that all the lowercase letter characters in the current 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

Sets the text spacing measured in twentieths of a point.

SetStrikeout

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

SetStyle

Sets the style to the current Range.

SetTextPr

Sets the text properties to the current Range.

SetUnderline

Specifies that the contents of the current 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

Specifies 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.
ToJSON

Converts the ApiRange object into the JSON object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var 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, 111, 61);
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, 111, 61);
oParagraph.GetRange(42, 44).SetStrikeout(true);
oParagraph.GetRange(7, 11).Delete();
builder.SaveFile("docx", "ApiRange.docx");
builder.CloseFile();

Resulting document