TRY NEW VERSION

Try now New API BETA

Try out the new view and capabilities of the API documentation

START

GetContent

GetContent(bGetCopies) → { Array }

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

Parameters:

Name Type Description
bGetCopies boolean

Specifies if the copies of the document elements will be returned or not.

Returns:

Type
Array

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 oShape = Api.CreateShape("rect", 100 * 36000, 100 * 36000, oFill, oStroke);
oParagraph.AddDrawing(oShape);
var oDocContent = oShape.GetDocContent();
oParagraph = Api.CreateParagraph();
oParagraph.AddText("This paragraph is the first document element.");
oDocContent.AddElement(0, oParagraph);
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered"));
var oTable = Api.CreateTable(2, 2);
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oDocContent.AddElement(1, oTable);
oParagraph = Api.CreateParagraph();
oParagraph.AddText("This table is the second document element.");
var oCell = oTable.GetCell(0,0);
oTable.AddElement(oCell, 0, oParagraph);
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement(0).AddText("This block text content control is the third document element.");
oDocContent.AddElement(2, oBlockLvlSdt);
var aDocElements = oDocContent.GetContent(false);
aDocElements[0].SetBold(true);
aDocElements[1].SetBackgroundColor(235, 235, 235, false);
aDocElements[2].Search("block text content control")[0].SetBold(true);
builder.SaveFile("docx", "GetContent.docx");
builder.CloseFile();

Resulting document