Get Started
Documentation

GetElementsCount

GetElementsCount() → {number}

Inherited From:

Get the number of elements in the current document.

Returns:

Type
number

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph;
oParagraph = oDocument.GetElement(0);
oParagraph.AddText("Number of document elements at this point: ");
oParagraph.AddTabStop();
oParagraph.AddText("" + oDocument.GetElementsCount());
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Now we add one more paragraph and push it.");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Number of document elements after we added the second paragraph ");
oParagraph.AddText("but before we push the third one: ");
oParagraph.AddTabStop();
oParagraph.AddText("" + oDocument.GetElementsCount());
oDocument.Push(oParagraph);
builder.SaveFile("docx", "GetElementsCount.docx");
builder.CloseFile();

Resulting document