跳到主要内容

AddText

向当前段落添加文本。

语法

expression.AddText(text);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
text必需string要插入到当前文档元素中的文本。

返回值

ApiRun

示例

此示例向段落添加一些文本。

// How to add a text to the ApiParagraph object.

// How to add a text to the shape.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const gs1 = Api.CreateGradientStop(Api.RGB(255, 213, 191), 0);
const gs2 = Api.CreateGradientStop(Api.RGB(255, 111, 61), 100000);
const fill = Api.CreateRadialGradientFill([gs1, gs2]);
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 150 * 36000, 65 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);

paragraph.SetJc("left");
paragraph.AddText("This is a text inside the shape aligned left.");
paragraph.AddLineBreak();
paragraph.AddText("This is a text after the line break.");
page.AddObject(shape);