跳到主要内容

RemoveElement

使用指定的位置移除元素。

继承自 ApiDocumentContent.RemoveElement。

语法​

expression.RemoveElement(nPos);

expression - 表示 ApiDocument 类的变量。

参数​

名称必需/可选数据类型默认值描述
nPos必需number元素在文档中或其他元素内部的编号(位置)。

返回值​

boolean

示例​

在文档中移除指定位置的段落。

// How do I delete a specific paragraph by its index in a document?

// Target and drop one paragraph out of several without affecting the rest in a document.

let doc = Api.GetDocument();
let paragraph0 = doc.GetElement(0);
paragraph0.AddText("This is paragraph #1.");
for (let i = 0; i < 4; ++i) {
let paragraph = Api.CreateParagraph();
paragraph.AddText("This is paragraph #" + (i + 2) + ".");
doc.Push(paragraph);
}
doc.RemoveElement(2);
let paragraph = Api.CreateParagraph();
paragraph.AddText("We removed paragraph #3, check that out above.");
doc.Push(paragraph);