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.

GetAllCharts

Returns a collection of chart objects from the document content.

GetAllDrawingObjects

Returns a collection of drawing objects from the document content.

GetAllImages

Returns a collection of image objects from the document content.

GetAllOleObjects

Returns a collection of OLE objects from the document content.

GetAllParagraphs

Returns an array of all paragraphs from the current document content.

GetAllShapes

Returns a collection of shape objects from the document content.

GetAllTables

Returns an array of all tables from the current document content.

GetClassType

Returns a type of the ApiDocumentContent class.

GetContent

Returns an array of document elements from the current ApiDocumentContent object.

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.

ToJSON

Converts the ApiDocumentContent object into the JSON object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
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