PowerPoint.ShapeFont class
表示形状的 TextRange 对象的字体属性,例如字体名称、字号和颜色。
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml
// Gets navigational (complex) properties of the selected text range.
await PowerPoint.run(async (context) => {
const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
textRange.load("font,paragraphFormat/bulletFormat,paragraphFormat/horizontalAlignment");
await context.sync();
console.log("Font properties of selected text range:");
console.log(`\tallCaps: ${textRange.font.allCaps}`);
console.log(`\tbold: ${textRange.font.bold}`);
console.log(`\tcolor: ${textRange.font.color}`);
console.log(`\tdoubleStrikethrough: ${textRange.font.doubleStrikethrough}`);
console.log(`\titalic: ${textRange.font.italic}`);
console.log(`\tname: ${textRange.font.name}`);
console.log(`\tsize: ${textRange.font.size}`);
console.log(`\tsmallCaps: ${textRange.font.smallCaps}`);
console.log(`\tstrikethrough: ${textRange.font.strikethrough}`);
console.log(`\tsubscript: ${textRange.font.subscript}`);
console.log(`\tsuperscript: ${textRange.font.superscript}`);
console.log(`\tunderline: ${textRange.font.underline}`);
console.log("Paragraph format properties of selected text range:");
console.log(`\tbulletFormat.visible: ${textRange.paragraphFormat.bulletFormat.visible}`);
console.log(`\thorizontalAlignment: ${textRange.paragraphFormat.horizontalAlignment}`);
});
属性
| all |
指定是否将 中的
|
| bold | 指定 中的文本
|
| color | 指定文本颜色 (的 HTML 颜色代码表示形式,例如,“#FF0000”表示红色) 。
|
| context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
| double |
指定 是否将 中的
|
| italic | 指定 中的文本
|
| name | 指定字体名称 (例如“Calibri”) 。 如果文本是复杂脚本或东亚语言,则这是相应的字体名称:否则为拉丁文字体名称。
|
| size | 指定字体大小(以磅为单位), (例如 11) 。
|
| small |
指定是否将 中的
|
| strikethrough | 指定 是否将 中的
|
| subscript | 指定 是否将 中的
|
| superscript | 指定 是否将 中的
|
| underline | 指定应用于字体的下划线类型。
|
方法
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| toJSON() | 重写 JavaScript |
属性详细信息
allCaps
指定是否将 中的 TextRange 文本设置为使用使小写字母显示为大写字母 的 All Caps 属性。 可能值包括:
true:所有文本都具有 All Caps 属性。false:没有文本具有 All Caps 属性。null:如果文本的某些(但不是全部)具有 All Caps 属性,则返回 。
allCaps: boolean | null;
属性值
boolean | null
注解
bold
指定 中的文本 TextRange 是否设置为粗体。 可能值包括:
true:所有文本都加粗。false:文本均不加粗。null:如果部分文本(但不是全部)为粗体,则返回 。
bold: boolean | null;
属性值
boolean | null
注解
color
指定文本颜色 (的 HTML 颜色代码表示形式,例如,“#FF0000”表示红色) 。
null如果 TextRange 包含不同颜色的文本片段,则返回 。
color: string | null;
属性值
string | null
注解
示例
// 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
doubleStrikethrough
指定 是否将 中的 TextRange 文本设置为使用 Double 删除线 属性。 可能值包括:
true:所有文本都具有 Double 删除线 属性。false:任何文本都没有 双删除线 属性。null:如果文本的某些(但不是全部)具有 Double 删除线 属性,则返回 。
doubleStrikethrough: boolean | null;
属性值
boolean | null
注解
italic
指定 中的文本 TextRange 是否设置为斜体。 可能值包括:
true:所有文本都斜体化。false:不对文本进行斜体化。null:如果文本的某些(但不是全部)被斜体化,则返回 。
italic: boolean | null;
属性值
boolean | null
注解
name
指定字体名称 (例如“Calibri”) 。 如果文本是复杂脚本或东亚语言,则这是相应的字体名称:否则为拉丁文字体名称。
null如果 TextRange 包含具有不同字体名称的文本片段,则返回 。
name: string | null;
属性值
string | null
注解
size
指定字体大小(以磅为单位), (例如 11) 。
null如果 TextRange 包含具有不同字号的文本片段,则返回 。
size: number | null;
属性值
number | null
注解
smallCaps
指定是否将 中的 TextRange 文本设置为使用 Small Caps 属性,该属性使小写字母显示为小写字母。 可能值包括:
true:所有文本都具有 Small Caps 属性。false:没有一个文本具有 Small Caps 属性。null:如果部分(但不是全部)文本具有 Small Caps 属性,则返回 。
smallCaps: boolean | null;
属性值
boolean | null
注解
strikethrough
指定 是否将 中的 TextRange 文本设置为使用 Strikethrough 属性。 可能值包括:
true:所有文本都具有 Strikethrough 属性。false:没有一个文本具有 Strikethrough 属性。null:如果文本的某些(但不是全部)具有 Strikethrough 属性,则返回 。
strikethrough: boolean | null;
属性值
boolean | null
注解
subscript
指定 是否将 中的 TextRange 文本设置为使用 Subscript 属性。 可能值包括:
true:所有文本都具有 Subscript 属性。false:文本中没有 下标 属性。null:如果文本的某些(但不是全部)具有 Subscript 属性,则返回 。
subscript: boolean | null;
属性值
boolean | null
注解
superscript
指定 是否将 中的 TextRange 文本设置为使用 Superscript 属性。 可能值包括:
true:所有文本都具有 上标 属性。false:文本中没有 上标 属性。null:如果文本的某些(但不是全部)具有 上标 属性,则返回 。
superscript: boolean | null;
属性值
boolean | null
注解
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
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/shapes.yaml
// This function gets the collection of shapes on the first slide,
// and adds a brace pair, {}, to the collection, while specifying its
// location and size. Then it names the shape, sets its text and font
// color, and centers it inside the braces.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
const braces: PowerPoint.Shape = shapes.addGeometricShape(PowerPoint.GeometricShapeType.bracePair, {
left: 100,
top: 400,
height: 50,
width: 150,
});
braces.name = "Braces";
braces.textFrame.textRange.text = "Shape text";
braces.textFrame.textRange.font.color = "purple";
braces.textFrame.textRange.font.underline = PowerPoint.ShapeFontUnderlineStyle.heavy;
braces.textFrame.verticalAlignment = PowerPoint.TextVerticalAlignment.middleCentered;
braces.textFrame.autoSizeSetting = PowerPoint.ShapeAutoSize.autoSizeShapeToFitText;
return context.sync();
});
方法详细信息
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: PowerPoint.Interfaces.ShapeFontLoadOptions): PowerPoint.ShapeFont;
参数
提供要加载对象的属性的选项。
返回
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;