跳到主要内容

InsertParagraph

在指定位置插入段落。

语法

expression.InsertParagraph(paragraph, sPosition, beRNewPara);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
paragraph必需string | ApiParagraph文本或段落。
sPosition必需string将插入文本或段落的位置(指定段落的「之前」或「之后」)。
beRNewPara必需boolean定义此方法是返回新段落(true)还是当前段落(false)。

返回值

ApiParagraph | null

示例

此示例在指定位置插入段落。

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

const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', 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.AddText('This is the first paragraph.');

const paragraph2 = Api.CreateParagraph();
paragraph2.AddText('This paragraph was inserted after the first one.');
paragraph.InsertParagraph(paragraph2, 'after', true);
slide.AddObject(shape);