Get Started
Usage API
More information

ApiDocumentContent

new ApiDocumentContent()

Class representing a container for paragraphs and tables.

Methods

Name Description
AddElement

Adds a paragraph or a table or a blockLvl content control using its position in the document content.

GetClassType

Returns a type of the ApiDocumentContent class.

GetElement

Returns an element by its position in the document.

GetElementsCount

Returns a number of elements in the current document.

GetRange

Returns a Range object that represents the part of the document contained in the document content.

Push

Pushes a paragraph or a table to actually add it to the document.

RemoveAllElements

Removes all the elements from the current document or from the current document element. When all elements are removed, a new empty paragraph is automatically created. If you want to add content to this paragraph, use the ApiDocumentContent.GetElement method.

RemoveElement

Removes an element using the position specified.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(104, 155, 104));
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke);
oParagraph.AddDrawing(oDrawing);
var oDocContent = oDrawing.GetDocContent();
oDocContent.RemoveAllElements();
oParagraph = oDocContent.GetElement(0);
oParagraph.AddText("We removed all elements from the shape and added a new paragraph inside it.");
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Number of elements inside the shape: " + oDocContent.GetElementsCount());
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ApiDocumentContent.docx");
builder.CloseFile();

Resulting document