跳到主要内容

AddElement

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

Syntax

expression.AddElement(nPos, oElement);

expression - A variable that represents a ApiDocumentContent class.

Parameters

NameRequired/OptionalData typeDefaultDescription
nPosRequirednumberThe position where the current element will be added.
oElementRequiredDocumentElementThe document element which will be added at the current position.

Returns

boolean

Example

This example adds a paragraph in document content.

// How to add text to the document using ApiParagraph.

// Update the document content adding a paragraph to it.

let worksheet = Api.GetActiveSheet();
let fill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = worksheet.AddShape("flowChartOnlineStorage", 200 * 36000, 60 * 36000, fill, stroke, 0, 2 * 36000, 0, 3 * 36000);
let content = shape.GetContent();
content.RemoveAllElements();
let paragraph = Api.CreateParagraph();
paragraph.AddText("We removed all elements from the shape and added a new paragraph inside it.");
content.AddElement(paragraph);
content.Push(paragraph);