跳到主要内容

GetElement

使用指定的位置返回段落元素。

语法

expression.GetElement(nPos);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
nPos必需number要获取其内容的元素必须位于的位置。

返回值

ParagraphContent

示例

此示例展示如何使用指定的位置获取段落元素。

// How to get the second element of the paragraph.

// Get the word from paragraph using its index and make it bold.

let doc = Api.GetDocument();
let paragraph = Api.CreateParagraph();
paragraph.RemoveAllElements();
let run = Api.CreateRun();
run.AddText("This is the text for the first text run. Do not forget a space at its end to separate from the second one. ");
paragraph.AddElement(run);
run = Api.CreateRun();
run.AddText("This is the text for the second run. We will set it bold afterwards. It also needs space at its end. ");
paragraph.AddElement(run);
run = Api.CreateRun();
run.AddText("This is the text for the third run. It ends the paragraph.");
paragraph.AddElement(run);
run = paragraph.GetElement(1);
run.SetBold(true);
doc.Push(paragraph);