跳到主要内容

Push

向当前段落添加元素。

语法

expression.Push(oElement);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
oElement必需ParagraphContent将在当前位置添加的文档元素。如果段落不支持 oElement 类型,则返回 false。

返回值

boolean

示例

此示例向段落添加元素。

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.HexColor('#FF6F3D'));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('roundRect', Api.MillimetersToEmus(300), Api.MillimetersToEmus(130), fill, stroke);
shape.SetPosition(Api.MillimetersToEmus(20), Api.MillimetersToEmus(35));
const docContent = shape.GetContent();
const paragraph = docContent.GetElement(0);
paragraph.RemoveAllElements();

let run = Api.CreateRun();
run.AddText('This is run #0, you must not push it to take effect. ');
paragraph.AddElement(run);
for (let i = 0; i < 5; i++) {
run = Api.CreateRun();
run.AddText('This is run #' + (i + 1) + '. ');
paragraph.Push(run);
}
slide.AddObject(shape);