跳到主要内容

Get

根据名称返回自定义属性的值。

语法

expression.Get(name);

expression - 表示 ApiCustomProperties 类的变量。

参数

名称必需/可选数据类型默认值描述
name必需string自定义属性名称。

返回值

string | number | Date | boolean | null

示例

此示例演示如何根据名称获取自定义属性的值。

const presentation = Api.GetPresentation();
const customProps = presentation.GetCustomProperties();

customProps.Add("ExistingProp", "#123456");

const existingProp = customProps.Get("ExistingProp");
const nonExistentProp = customProps.Get("NonExistentProp");

const fill = Api.CreateSolidFill(Api.RGB(150, 200, 150));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', 300 * 36000, 100 * 36000, fill, stroke);
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();
slide.AddObject(shape);

let paragraph = shape.GetDocContent().GetElement(0);
paragraph.AddText("Existing Property Value: " + existingProp);
paragraph.AddText("\nNon-Existent Property Value: " + nonExistentProp);