跳到主要内容

GetLayoutByType

返回与幻灯片母版的指定版式类型对应的版式。

语法

expression.GetLayoutByType(sType);

expression - 表示 ApiMaster 类的变量。

参数

名称必需/可选数据类型默认值描述
sType必需LayoutType版式类型。

返回值

ApiLayout | null

示例

此示例根据类型从幻灯片母版返回布局。

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

const master = presentation.GetMaster(0);
const layout = master.GetLayoutByType('title');

const fill = Api.CreateSolidFill(Api.RGB(216, 228, 188));
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);
if (layout) {
paragraph.AddText('Layout found: ' + layout.GetClassType());
} else {
paragraph.AddText('Layout not found.');
}
slide.AddObject(shape);