Get Started
Documentation

GetElementsCount

GetElementsCount() → { number }

Get the number of elements in the current inline text content control. The text content control is created with one text run present in it by default, so any even without any element added this method will return the value of '1'.

Returns:

Type
number

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph, oRun, oRun1;
oParagraph = oDocument.GetElement(0);
oInlineLvlSdt = Api.CreateInlineLvlSdt();
oParagraph.AddInlineLvlSdt(oInlineLvlSdt);
oParagraph.AddLineBreak();
oInlineLvlSdtCount = oInlineLvlSdt.GetElementsCount();
oParagraph.AddText("Number of elements in oInlineLvlSdt (before adding anything) = " + oInlineLvlSdtCount);
oRun = Api.CreateRun();
oRun.AddText("This is an inline text content control. ");
oInlineLvlSdt.AddElement(oRun, 0);
oParagraph.AddLineBreak();
oInlineLvlSdtCount = oInlineLvlSdt.GetElementsCount();
oParagraph.AddText("Number of elements in oInlineLvlSdt (after adding one element) = " + oInlineLvlSdtCount);
oRun1 = Api.CreateRun();
oRun1.AddText("One more element of the inline text content control.");
oInlineLvlSdt.AddElement(oRun1, 1);
oInlineLvlSdtCount = oInlineLvlSdt.GetElementsCount();
oParagraph.AddLineBreak();
oParagraph.AddText("Number of elements in oInlineLvlSdt (after adding one more element) = " + oInlineLvlSdtCount);
builder.SaveFile("docx", "GetElementsCount.docx");
builder.CloseFile();

Resulting document