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");
const parentTextFrame: PowerPoint.TextFrame = textRange.getParentTextFrame();
const parentShape: PowerPoint.Shape = parentTextFrame.getParentShape();
const parentSlide: PowerPoint.Slide = parentShape.getParentSlide();
parentShape.load("id");
parentSlide.load("id");
await context.sync();
console.log(`Selected text range found in parent shape with ID ${parentShape.id} on parentSlide with ID ${parentSlide.id}`);
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 文本设置为使用 “全部大写 ”属性,该属性使小写字母显示为大写字母。 可能值包括:
true:所有文本都具有 “全部大写” 属性。false:所有文本均不具有 “全部大写” 属性。null:如果部分(但不是全部)文本具有 “全部大写 ”属性,则返回。
allCaps: boolean | null;
属性值
boolean | null
注解
bold
指定中的 TextRange 文本是否设置为粗体。 可能值包括:
true:所有文本均为粗体。false:没有任何文本是粗体的。null:如果部分(但不是全部)文本为粗体,则返回。
bold: boolean | null;
属性值
boolean | null
注解
color
指定文本颜色 (的 HTML 颜色代码表示形式,例如,“#FF0000”表示红色) 。 如果包含TextRange不同颜色的文本片段,则返回null。
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 文本设置为使用 “双删除线 ”属性。 可能值包括:
true:所有文本都具有 双删除线 属性。false:没有任何文本具有 双删除 线属性。null:如果部分(但不是全部)文本具有 双删除 线属性,则返回。
doubleStrikethrough: boolean | null;
属性值
boolean | null
注解
italic
指定是否将 中的 TextRange 文本设置为斜体。 可能值包括:
true:所有文本均为斜体。false:所有文本均不以斜体表示。null:如果部分(但不是全部)文本为斜体,则返回。
italic: boolean | null;
属性值
boolean | null
注解
name
指定字体名称 (例如“Calibri”) 。 如果文本是复杂脚本或东亚语言,则这是相应的字体名称;否则,它是拉丁字体名称。 如果包含TextRange具有不同字体名称的文本片段,则返回null。
name: string | null;
属性值
string | null
注解
size
指定字号(以磅为单位 (例如 11) 。 如果包含TextRange具有不同字体大小的文本片段,则返回null。
size: number | null;
属性值
number | null
注解
smallCaps
指定是否将 中的 TextRange 文本设置为使用 “小型大写 ”属性,该属性使小写字母显示为小型大写字母。 可能值包括:
true:所有文本都具有 小型大写 属性。false:没有文本具有 小型大写 属性。null:如果部分(但不是全部)文本具有 小型大写 属性,则返回。
smallCaps: boolean | null;
属性值
boolean | null
注解
strikethrough
指定是否 TextRange 将 中的文本设置为使用 删除线 属性。 可能值包括:
true:所有文本都具有 删除线 属性。false:没有文本具有 删除 线属性。null:如果部分(但不是全部)文本具有 删除线 属性,则返回。
strikethrough: boolean | null;
属性值
boolean | null
注解
subscript
指定是否将 中的 TextRange 文本设置为使用 下标 属性。 可能值包括:
true:所有文本都具有下 标 属性。false:没有任何文本具有下 标 属性。null:如果部分(但不是全部)文本具有下 标 属性,则返回。
subscript: boolean | null;
属性值
boolean | null
注解
superscript
指定是否将 中的 TextRange 文本设置为使用 “上标 ”属性。 可能值包括:
true:所有文本都具有 上标 属性。false:没有任何文本具有 上标 属性。null:如果部分(但不是全部)文本具有 上标 属性,则返回。
superscript: boolean | null;
属性值
boolean | null
注解
underline
指定应用于字体的下划线类型。 如果包含TextRange具有不同下划线样式的文本片段,则返回null。 有关详细信息,请参阅 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;