跳到主要内容

GetElement

通过元素在文档中的位置返回元素。

语法

expression.GetElement(nPos);

expression - 表示 ApiDocumentContent 类的变量。

参数

名称必需/可选数据类型默认值描述
nPos必需number将从文档中获取的元素位置。

返回值

DocumentElement

示例

此示例展示如何通过元素在文档内容中的位置获取元素。

// How to get an element of the document content knowing its index position.

// Get a document element then change its position and content.

let worksheet = Api.GetActiveSheet();
let fill = Api.CreateSolidFill(Api.RGB(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);
let paraPr = paragraph.GetParaPr();
paraPr.SetJc("center");
paragraph.AddText("This is a paragraph with the text in it aligned by the center. ");
paragraph.AddText("The justification is specified in the paragraph style. ");
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
paragraph.AddText("These sentences are used to add lines for demonstrative purposes.");