Get Started
Usage API
More information

ApiRun

new ApiRun()

Class representing a small text block called 'run'.

Methods

Name Description
AddLineBreak

Adds a line break to the current run position and starts the next element from a new line.

AddTabStop

Adds a tab stop to the current run.

AddText

Adds some text to the current run.

ClearContent

Clears the content from the current run.

Copy

Creates a copy of the current run.

Delete

Deletes the current run.

GetClassType

Returns a type of the ApiRun class.

GetFontNames

Returns all font names from all elements inside the current run.

GetTextPr

Returns the text properties of the current run.

RemoveAllElements

Removes all the elements from the current run.

SetBold

Sets the bold property to the text character.

SetCaps

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

SetColor

Sets the text color for the current text run in the RGB format.

SetDoubleStrikeout

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

SetFill

Sets the text color to the current text run.

SetFontFamily

Sets all 4 font slots with the specified font family.

SetFontSize

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

SetHighlight

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

SetItalic

Sets the italic property to the text character.

SetLanguage

Specifies the languages which will be used to check spelling and grammar (if requested) when processing the contents of this text run.

SetOutLine

Sets the text outline to the current text run.

SetPosition

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

SetShd

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

SetSmallCaps

Specifies that all the small letter characters in this text run 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 run are displayed with a single horizontal line through the center of the line.

SetStyle

Sets a style to the current run.

SetTextFill

Sets the text fill to the current text run.

SetTextPr

Sets the text properties to the current run.

SetUnderline

Specifies that the contents of the current run 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 contents of the current run in relation to the default appearance of the text run:

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

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(104, 155, 104));
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oShape = oWorksheet.AddShape("flowChartOnlineStorage", 120 * 36000, 70 * 36000, oFill, oStroke, 0, 2 * 36000, 0, 3 * 36000);
var oDocContent = oShape.GetContent();
var oParagraph = oDocContent.GetElement(0);
var oRun = Api.CreateRun();
oRun.AddText("This is the text for the first line. Nothing special.");
oRun.AddLineBreak();
oRun.AddText("This is the text which starts from the beginning of the second line. After it three tab stops will be added.");
oRun.AddTabStop();
oRun.AddTabStop();
oRun.AddTabStop();
oRun.AddText("This is the text which starts after the tab stops.");
oRun.SetItalic(true);
oParagraph.AddElement(oRun);
oRun = Api.CreateRun();
var oTextPr = oRun.GetTextPr();
oTextPr.SetFontSize(30);
oRun.AddText("This is just a sample text. ");
oRun.AddText("But you will not see it in the resulting document, as it will be cleared.");
oParagraph.AddElement(oRun);
oRun.ClearContent();
oParagraph = Api.CreateParagraph();
oRun = Api.CreateRun();
oRun.AddText("The text in the previous paragraph cannot be seen, as it has been cleared.");
oParagraph.AddElement(oRun);
oRun = Api.CreateRun();
oRun.AddLineBreak();
oRun.AddText("This is just a sample text that was copied.");
oParagraph.AddElement(oRun);
var oCopyRun = oRun.Copy();
oCopyRun.SetCaps(true);
oCopyRun.SetBold(true);
oCopyRun.SetFontSize(20);
var sClassType = oCopyRun.GetClassType();
oCopyRun.AddLineBreak();
oCopyRun.AddText("Class Type = " + sClassType);
oParagraph.AddElement(oCopyRun);
oDocContent.Push(oParagraph);
builder.SaveFile("xlsx", "ApiRun.xlsx");
builder.CloseFile();

Resulting document