跳到主要内容

GetStyle

按名称返回样式。

语法​

expression.GetStyle(styleName);

expression - 表示 ApiDocument 类的变量。

参数​

名称必需/可选数据类型默认值描述
styleName必需string样式名称。

返回值​

ApiStyle | null

示例​

按名称获取内置样式并将其应用于文档中的段落。

// How do I retrieve and apply a built-in heading style in a document?

// Reuse an existing style from the style gallery to format text without defining custom properties.

let doc = Api.GetDocument();
let noSpacingStyle = doc.GetStyle("Heading 6");
let paragraph = doc.GetElement(0);
paragraph.SetStyle(noSpacingStyle);
paragraph.AddText("This is a text in a paragraph styled with the 'Heading 6' style.");