Skip to main content

RemoveElement

Removes an element using the position specified.

Syntax

expression.RemoveElement(nPos);

expression - A variable that represents a ApiDocumentContent class.

Parameters

NameRequired/OptionalData typeDefaultDescription
nPosRequirednumberThe element number (position) in the document or inside other element.

Returns

boolean

Example

This example removes an element using the position specified.

// How to remove an element from a document knowing its position in the document content.

// Delete an element from a document and prove it by showing the difference.

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();
let paragraph = content.GetElement(0);
paragraph.AddText("This is paragraph #1.");
for (let paraIncrease = 1; paraIncrease < 5; ++paraIncrease) {
paragraph = Api.CreateParagraph();
paragraph.AddText("This is paragraph #" + (paraIncrease + 1) + ".");
content.Push(paragraph);
}
content.RemoveElement(2);
paragraph = Api.CreateParagraph();
paragraph.AddText("We removed paragraph #3, check that out above.");
content.Push(paragraph);