PowerPoint.ShapeFont class

表示形状的 TextRange 对象的字体属性,例如字体名称、字号和颜色。

扩展

注解

[ API 集:PowerPointApi 1.4 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

属性

allCaps

指定是否将 中的 TextRange 文本设置为使用使小写字母显示为大写字母 的 All Caps 属性。 可能值包括:

  • true :所有文本都具有 All Caps 属性。

  • false :没有文本具有 All Caps 属性。

  • null :如果文本的某些(但不是全部)具有 All Caps 属性,则返回 。

bold

指定 中的文本 TextRange 是否设置为粗体。 可能值包括:

  • true :所有文本都加粗。

  • false :文本均不加粗。

  • null :如果部分文本(但不是全部)为粗体,则返回 。

color

指定文本颜色 (的 HTML 颜色代码表示形式,例如,“#FF0000”表示红色) 。 null如果 TextRange 包含不同颜色的文本片段,则返回 。

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

doubleStrikethrough

指定 是否将 中的 TextRange 文本设置为使用 Double 删除线 属性。 可能值包括:

  • true :所有文本都具有 Double 删除线 属性。

  • false :任何文本都没有 双删除线 属性。

  • null :如果文本的某些(但不是全部)具有 Double 删除线 属性,则返回 。

italic

指定 中的文本 TextRange 是否设置为斜体。 可能值包括:

  • true :所有文本都斜体化。

  • false :不对文本进行斜体化。

  • null :如果文本的某些(但不是全部)被斜体化,则返回 。

name

指定字体名称 (例如“Calibri”) 。 如果文本是复杂脚本或东亚语言,则这是相应的字体名称:否则为拉丁文字体名称。 null如果 TextRange 包含具有不同字体名称的文本片段,则返回 。

size

指定字体大小(以磅为单位), (例如 11) 。 null如果 TextRange 包含具有不同字号的文本片段,则返回 。

smallCaps

指定是否将 中的 TextRange 文本设置为使用 Small Caps 属性,该属性使小写字母显示为小写字母。 可能值包括:

  • true :所有文本都具有 Small Caps 属性。

  • false :没有一个文本具有 Small Caps 属性。

  • null :如果部分(但不是全部)文本具有 Small Caps 属性,则返回 。

strikethrough

指定 是否将 中的 TextRange 文本设置为使用 Strikethrough 属性。 可能值包括:

  • true :所有文本都具有 Strikethrough 属性。

  • false :没有一个文本具有 Strikethrough 属性。

  • null :如果文本的某些(但不是全部)具有 Strikethrough 属性,则返回 。

subscript

指定 是否将 中的 TextRange 文本设置为使用 Subscript 属性。 可能值包括:

  • true :所有文本都具有 Subscript 属性。

  • false :文本中没有 下标 属性。

  • null :如果文本的某些(但不是全部)具有 Subscript 属性,则返回 。

superscript

指定 是否将 中的 TextRange 文本设置为使用 Superscript 属性。 可能值包括:

  • true :所有文本都具有 上标 属性。

  • false :文本中没有 上标 属性。

  • null :如果文本的某些(但不是全部)具有 上标 属性,则返回 。

underline

指定应用于字体的下划线类型。 null如果 TextRange 包含具有不同下划线样式的文本片段,则返回 。 有关详细信息 ,请参阅 PowerPoint.ShapeFontUnderlineStyle

方法

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,依次调用toJSON传递给它的 对象的 方法。) 虽然原始PowerPoint.ShapeFont对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 PowerPoint.Interfaces.ShapeFontData) ,其中包含从原始对象加载的任何子属性的浅表副本。

属性详细信息

allCaps

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定是否将 中的 TextRange 文本设置为使用使小写字母显示为大写字母 的 All Caps 属性。 可能值包括:

  • true :所有文本都具有 All Caps 属性。

  • false :没有文本具有 All Caps 属性。

  • null :如果文本的某些(但不是全部)具有 All Caps 属性,则返回 。

allCaps: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

bold

指定 中的文本 TextRange 是否设置为粗体。 可能值包括:

  • true :所有文本都加粗。

  • false :文本均不加粗。

  • null :如果部分文本(但不是全部)为粗体,则返回 。

bold: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi 1.4 ]

color

指定文本颜色 (的 HTML 颜色代码表示形式,例如,“#FF0000”表示红色) 。 null如果 TextRange 包含不同颜色的文本片段,则返回 。

color: string | null;

属性值

string | null

注解

[ API 集:PowerPointApi 1.4 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

doubleStrikethrough

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定 是否将 中的 TextRange 文本设置为使用 Double 删除线 属性。 可能值包括:

  • true :所有文本都具有 Double 删除线 属性。

  • false :任何文本都没有 双删除线 属性。

  • null :如果文本的某些(但不是全部)具有 Double 删除线 属性,则返回 。

doubleStrikethrough: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

italic

指定 中的文本 TextRange 是否设置为斜体。 可能值包括:

  • true :所有文本都斜体化。

  • false :不对文本进行斜体化。

  • null :如果文本的某些(但不是全部)被斜体化,则返回 。

italic: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi 1.4 ]

name

指定字体名称 (例如“Calibri”) 。 如果文本是复杂脚本或东亚语言,则这是相应的字体名称:否则为拉丁文字体名称。 null如果 TextRange 包含具有不同字体名称的文本片段,则返回 。

name: string | null;

属性值

string | null

注解

[ API 集:PowerPointApi 1.4 ]

size

指定字体大小(以磅为单位), (例如 11) 。 null如果 TextRange 包含具有不同字号的文本片段,则返回 。

size: number | null;

属性值

number | null

注解

[ API 集:PowerPointApi 1.4 ]

smallCaps

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定是否将 中的 TextRange 文本设置为使用 Small Caps 属性,该属性使小写字母显示为小写字母。 可能值包括:

  • true :所有文本都具有 Small Caps 属性。

  • false :没有一个文本具有 Small Caps 属性。

  • null :如果部分(但不是全部)文本具有 Small Caps 属性,则返回 。

smallCaps: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

strikethrough

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定 是否将 中的 TextRange 文本设置为使用 Strikethrough 属性。 可能值包括:

  • true :所有文本都具有 Strikethrough 属性。

  • false :没有一个文本具有 Strikethrough 属性。

  • null :如果文本的某些(但不是全部)具有 Strikethrough 属性,则返回 。

strikethrough: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

subscript

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定 是否将 中的 TextRange 文本设置为使用 Subscript 属性。 可能值包括:

  • true :所有文本都具有 Subscript 属性。

  • false :文本中没有 下标 属性。

  • null :如果文本的某些(但不是全部)具有 Subscript 属性,则返回 。

subscript: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

superscript

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定 是否将 中的 TextRange 文本设置为使用 Superscript 属性。 可能值包括:

  • true :所有文本都具有 上标 属性。

  • false :文本中没有 上标 属性。

  • null :如果文本的某些(但不是全部)具有 上标 属性,则返回 。

superscript: boolean | null;

属性值

boolean | null

注解

[ API 集:PowerPointApi BETA (仅预览版) ]

underline

指定应用于字体的下划线类型。 null如果 TextRange 包含具有不同下划线样式的文本片段,则返回 。 有关详细信息 ,请参阅 PowerPoint.ShapeFontUnderlineStyle

underline: PowerPoint.ShapeFontUnderlineStyle | "None" | "Single" | "Double" | "Heavy" | "Dotted" | "DottedHeavy" | "Dash" | "DashHeavy" | "DashLong" | "DashLongHeavy" | "DotDash" | "DotDashHeavy" | "DotDotDash" | "DotDotDashHeavy" | "Wavy" | "WavyHeavy" | "WavyDouble" | null;

属性值

PowerPoint.ShapeFontUnderlineStyle | "None" | "Single" | "Double" | "Heavy" | "Dotted" | "DottedHeavy" | "Dash" | "DashHeavy" | "DashLong" | "DashLongHeavy" | "DotDash" | "DotDashHeavy" | "DotDotDash" | "DotDotDashHeavy" | "Wavy" | "WavyHeavy" | "WavyDouble" | null

注解

[ API 集:PowerPointApi 1.4 ]

方法详细信息

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: PowerPoint.Interfaces.ShapeFontLoadOptions): PowerPoint.ShapeFont;

参数

options
PowerPoint.Interfaces.ShapeFontLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): PowerPoint.ShapeFont;

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.ShapeFont;

参数

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,依次调用toJSON传递给它的 对象的 方法。) 虽然原始PowerPoint.ShapeFont对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 PowerPoint.Interfaces.ShapeFontData) ,其中包含从原始对象加载的任何子属性的浅表副本。

toJSON(): PowerPoint.Interfaces.ShapeFontData;

返回