Word.Font class
表示字体。
注解
示例
// Change the font color
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to change the font color of the current selection.
selection.font.color = 'blue';
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The font color of the selection has been changed.');
});
属性
| all |
指定字体的格式是否设置为所有大写字母,这会使小写字母显示为大写字母。 可能值包括:
|
| bold | 指定字体是否为粗体。
|
| bold |
指定字体是否在从右到左的语言文档中设置为粗体。 可能值包括:
|
| borders | 返回一个 |
| color | 指定字体的颜色。 可以采用“#RRGGBB”格式或颜色名称提供值。 |
| color |
指定一个 |
| color |
指定从右到左语言文档中对象的颜色 |
| context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
| contextual |
指定是否为字体启用上下文替换。 |
| diacritic |
指定要用于对象的音调符号 |
| disable |
指定Microsoft Word是否忽略相应 |
| double |
指定字体是否具有双删除线。
|
| emboss | 指定字体的格式是否为浮雕。 可能值包括:
|
| emphasis |
指定一个 |
| engrave | 指定字体的格式是否为刻字。 可能值包括:
|
| fill | 返回一个 |
| glow | 返回一个 |
| hidden | 指定字体是否标记为隐藏。
|
| highlight |
指定突出显示颜色。 若要设置它,请使用“#RRGGBB”格式或颜色名称的值。 若要删除突出显示颜色,请将其设置为 |
| italic | 指定字体是否斜体。
|
| italic |
指定字体是否在从右到左的语言文档中斜体。 可能值包括:
|
| kerning | 指定Microsoft Word自动调整字距的最小字号。 |
| ligature | 指定 对象的连字设置 |
| line | 返回一个 |
| name | 指定字体的名称。 |
| name |
指定用于拉丁文文本 (字符的字体,其字符代码从 0 (零) 到 127) 。 |
| name |
指定从右到左语言文档中的字体名称。 |
| name |
指定东亚字体名称。 |
| name |
指定用于代码介于 128 到 255 的字符的字体。 |
| number |
指定 OpenType 字体的数字形式设置。 |
| number |
指定字体的数字间距设置。 |
| outline | 指定字体的格式是否为大纲格式。 可能值包括:
|
| position | 指定文本 (相对于底线) 磅的位置。 |
| reflection | 返回一个 |
| scaling | 指定应用于字体的缩放百分比。 |
| shadow | 指定字体的格式是否为阴影。 可能值包括:
|
| size | 指定字号(以磅为单位)。 |
| size |
指定从右到左的文本的字号(以磅为单位)。 |
| small |
指定字体的格式是否设置为小写字母,使小写字母显示为小写字母。 可能值包括:
|
| spacing | 指定字符之间的间距。 |
| strike |
指定字体是否具有删除线。
|
| stylistic |
指定字体的样式集。 |
| subscript | 指定字体是否为下标。
|
| superscript | 指定字体是否为上标。
|
| text |
返回一个 |
| text |
返回一个 |
| three |
返回一个 |
| underline | 指定字体的下划线类型。
|
| underline |
指定对象的下划线 |
方法
| decrease |
将字号减小为下一个可用的字号。 |
| increase |
将字号增大为下一个可用的字号。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| reset() | 删除手动字符格式。 |
| set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。 |
| set(properties) | 基于现有的已加载对象,同时对对象设置多个属性。 |
| set |
将指定的字体格式设置为活动文档和所有基于活动模板创建的新文档的默认格式。 |
| toJSON() | 重写 JavaScript |
| track() | 根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 |
| untrack() | 释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用 |
属性详细信息
allCaps
指定字体的格式是否设置为所有大写字母,这会使小写字母显示为大写字母。 可能值包括:
true:所有文本都具有 All Caps 属性。false:没有文本具有 All Caps 属性。null:如果文本的某些(但不是全部)具有 All Caps 属性,则返回 。
allCaps: boolean;
属性值
boolean
注解
bold
指定字体是否为粗体。
true 如果字体的格式设置为粗体,则为 ;否则为 false。
bold: boolean;
属性值
boolean
注解
示例
// Bold format text
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to make the current selection bold.
selection.font.bold = true;
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The selection is now bold.');
});
boldBidirectional
指定字体是否在从右到左的语言文档中设置为粗体。 可能值包括:
true:所有文本都加粗。false:文本均不加粗。null:如果部分文本(但不是全部)为粗体,则返回 。
boldBidirectional: boolean;
属性值
boolean
注解
borders
返回一个 BorderUniversalCollection 对象,该对象代表字体的所有边框。
readonly borders: Word.BorderUniversalCollection;
属性值
注解
color
指定字体的颜色。 可以采用“#RRGGBB”格式或颜色名称提供值。
color: string;
属性值
string
注解
示例
// Change the font color
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to change the font color of the current selection.
selection.font.color = 'blue';
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The font color of the selection has been changed.');
});
colorIndex
指定一个 ColorIndex 值,该值表示字体的颜色。
colorIndex: Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor";
属性值
Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor"
注解
colorIndexBidirectional
指定从右到左语言文档中对象的颜色 Font 。
colorIndexBidirectional: Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor";
属性值
Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor"
注解
context
contextualAlternates
diacriticColor
指定要用于对象的音调符号 Font 的颜色。 可以采用“#RRGGBB”格式提供值。
diacriticColor: string;
属性值
string
注解
disableCharacterSpaceGrid
指定Microsoft Word是否忽略相应Font对象的每行字符数。
disableCharacterSpaceGrid: boolean;
属性值
boolean
注解
doubleStrikeThrough
指定字体是否具有双删除线。
true 如果字体的格式设置为双删除线文本,则为 ;否则为 false。
doubleStrikeThrough: boolean;
属性值
boolean
注解
emboss
指定字体的格式是否为浮雕。 可能值包括:
true:所有文本都已浮雕。false:文本均未浮雕。null:如果部分(但不是全部)文本已浮雕,则返回 。
emboss: boolean;
属性值
boolean
注解
emphasisMark
指定一个 EmphasisMark 值,该值代表字符或指定字符串的强调标记。
emphasisMark: Word.EmphasisMark | "None" | "OverSolidCircle" | "OverComma" | "OverWhiteCircle" | "UnderSolidCircle";
属性值
Word.EmphasisMark | "None" | "OverSolidCircle" | "OverComma" | "OverWhiteCircle" | "UnderSolidCircle"
注解
engrave
指定字体的格式是否为刻字。 可能值包括:
true:所有文本都已刻字。false:不刻任何文本。null:如果部分(但不是全部)刻有文本,则返回 。
engrave: boolean;
属性值
boolean
注解
fill
返回一个 FillFormat 对象,该对象包含文本区域使用的字体的填充格式属性。
readonly fill: Word.FillFormat;
属性值
注解
glow
返回一个 GlowFormat 对象,该对象代表文本区域使用的字体的发光格式。
readonly glow: Word.GlowFormat;
属性值
注解
hidden
指定字体是否标记为隐藏。
true 如果字体的格式设置为隐藏文本,则为 ;否则为 false。
hidden: boolean;
属性值
boolean
注解
highlightColor
指定突出显示颜色。 若要设置它,请使用“#RRGGBB”格式或颜色名称的值。 若要删除突出显示颜色,请将其设置为 null。 返回的突出显示颜色可以是“#RRGGBB”格式、混合突出显示颜色的空字符串或 null 无突出显示颜色。 注意:Office for Windows Desktop 中只有默认突出显示颜色可用。 这些是“黄色”、“石灰”、“绿松石”、“粉色”、“蓝色”、“红色”、“深蓝色”、“青青”、“绿色”、“紫色”、“深红”、“橄榄”、“灰色”、“LightGray”和“黑色”。 当加载项在 Office for Windows 桌面版中运行时,任何其他颜色在应用于字体时将转换为最接近的颜色。
highlightColor: string;
属性值
string
注解
示例
// Highlight selected text
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to highlight the current selection.
selection.font.highlightColor = '#FFFF00'; // Yellow
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The selection has been highlighted.');
});
italic
italicBidirectional
指定字体是否在从右到左的语言文档中斜体。 可能值包括:
true:所有文本都斜体化。false:不对文本进行斜体化。null:如果文本的某些(但不是全部)被斜体化,则返回 。
italicBidirectional: boolean;
属性值
boolean
注解
kerning
ligature
指定 对象的连字设置 Font 。
ligature: Word.Ligature | "None" | "Standard" | "Contextual" | "StandardContextual" | "Historical" | "StandardHistorical" | "ContextualHistorical" | "StandardContextualHistorical" | "Discretional" | "StandardDiscretional" | "ContextualDiscretional" | "StandardContextualDiscretional" | "HistoricalDiscretional" | "StandardHistoricalDiscretional" | "ContextualHistoricalDiscretional" | "All";
属性值
Word.Ligature | "None" | "Standard" | "Contextual" | "StandardContextual" | "Historical" | "StandardHistorical" | "ContextualHistorical" | "StandardContextualHistorical" | "Discretional" | "StandardDiscretional" | "ContextualDiscretional" | "StandardContextualDiscretional" | "HistoricalDiscretional" | "StandardHistoricalDiscretional" | "ContextualHistoricalDiscretional" | "All"
注解
line
返回一个 LineFormat 对象,该对象指定行的格式。
readonly line: Word.LineFormat;
属性值
注解
name
指定字体的名称。
name: string;
属性值
string
注解
示例
// Change the font name
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to change the current selection's font name.
selection.font.name = 'Arial';
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The font name has changed.');
});
nameAscii
指定用于拉丁文文本 (字符的字体,其字符代码从 0 (零) 到 127) 。
nameAscii: string;
属性值
string
注解
nameBidirectional
nameFarEast
nameOther
numberForm
指定 OpenType 字体的数字形式设置。
numberForm: Word.NumberForm | "Default" | "Lining" | "OldStyle";
属性值
Word.NumberForm | "Default" | "Lining" | "OldStyle"
注解
numberSpacing
指定字体的数字间距设置。
numberSpacing: Word.NumberSpacing | "Default" | "Proportional" | "Tabular";
属性值
Word.NumberSpacing | "Default" | "Proportional" | "Tabular"
注解
outline
指定字体的格式是否为大纲格式。 可能值包括:
true:所有文本都已大纲显示。false:未列出任何文本。null:如果部分文本(但不是全部)已大纲显示,则返回 。
outline: boolean;
属性值
boolean
注解
position
reflection
返回一个 ReflectionFormat 对象,该对象代表形状的反射格式。
readonly reflection: Word.ReflectionFormat;
属性值
注解
scaling
shadow
指定字体的格式是否为阴影。 可能值包括:
true:所有文本都隐藏。false:文本均不隐藏。null:如果部分(但不是全部)文本被隐藏,则返回 。
shadow: boolean;
属性值
boolean
注解
size
指定字号(以磅为单位)。
size: number;
属性值
number
注解
示例
// Change the font size
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to change the current selection's font size.
selection.font.size = 20;
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The font size has changed.');
});
sizeBidirectional
smallCaps
指定字体的格式是否设置为小写字母,使小写字母显示为小写字母。 可能值包括:
true:所有文本都具有 Small Caps 属性。false:没有一个文本具有 Small Caps 属性。null:如果部分(但不是全部)文本具有 Small Caps 属性,则返回 。
smallCaps: boolean;
属性值
boolean
注解
spacing
strikeThrough
指定字体是否具有删除线。
true 如果字体的格式设置为删除线文本,则为 ;否则为 false。
strikeThrough: boolean;
属性值
boolean
注解
示例
// Strike format text
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to strikethrough the font of the current selection.
selection.font.strikeThrough = true;
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The selection now has a strikethrough.');
});
stylisticSet
指定字体的样式集。
stylisticSet: Word.StylisticSet | "Default" | "Set01" | "Set02" | "Set03" | "Set04" | "Set05" | "Set06" | "Set07" | "Set08" | "Set09" | "Set10" | "Set11" | "Set12" | "Set13" | "Set14" | "Set15" | "Set16" | "Set17" | "Set18" | "Set19" | "Set20";
属性值
Word.StylisticSet | "Default" | "Set01" | "Set02" | "Set03" | "Set04" | "Set05" | "Set06" | "Set07" | "Set08" | "Set09" | "Set10" | "Set11" | "Set12" | "Set13" | "Set14" | "Set15" | "Set16" | "Set17" | "Set18" | "Set19" | "Set20"
注解
subscript
指定字体是否为下标。
true 如果字体的格式设置为下标,则为 ;否则为 false。
subscript: boolean;
属性值
boolean
注解
superscript
指定字体是否为上标。
true 如果字体的格式设置为上标,则为 ;否则为 false。
superscript: boolean;
属性值
boolean
注解
textColor
返回一个 ColorFormat 对象,该对象代表字体的颜色。
readonly textColor: Word.ColorFormat;
属性值
注解
textShadow
返回一个 ShadowFormat 对象,该对象指定字体的阴影格式。
readonly textShadow: Word.ShadowFormat;
属性值
注解
threeDimensionalFormat
返回一个 ThreeDimensionalFormat 对象,该对象包含字体的三维 (三维) 效果格式属性。
readonly threeDimensionalFormat: Word.ThreeDimensionalFormat;
属性值
注解
underline
指定字体的下划线类型。
none 如果字体没有下划线,则为 。
underline: Word.UnderlineType | "Mixed" | "None" | "Hidden" | "DotLine" | "Single" | "Word" | "Double" | "Thick" | "Dotted" | "DottedHeavy" | "DashLine" | "DashLineHeavy" | "DashLineLong" | "DashLineLongHeavy" | "DotDashLine" | "DotDashLineHeavy" | "TwoDotDashLine" | "TwoDotDashLineHeavy" | "Wave" | "WaveHeavy" | "WaveDouble";
属性值
Word.UnderlineType | "Mixed" | "None" | "Hidden" | "DotLine" | "Single" | "Word" | "Double" | "Thick" | "Dotted" | "DottedHeavy" | "DashLine" | "DashLineHeavy" | "DashLineLong" | "DashLineLongHeavy" | "DotDashLine" | "DotDashLineHeavy" | "TwoDotDashLine" | "TwoDotDashLineHeavy" | "Wave" | "WaveHeavy" | "WaveDouble"
注解
示例
// Underline format text
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a range proxy object for the current selection.
const selection = context.document.getSelection();
// Queue a command to underline the current selection.
selection.font.underline = Word.UnderlineType.single;
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The selection now has an underline style.');
});
underlineColor
指定对象的下划线 Font 颜色。 可以采用“#RRGGBB”格式提供值。
underlineColor: string;
属性值
string
注解
方法详细信息
decreaseFontSize()
increaseFontSize()
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: Word.Interfaces.FontLoadOptions): Word.Font;
参数
- options
- Word.Interfaces.FontLoadOptions
提供要加载对象的属性的选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Word.Font;
参数
- propertyNames
-
string | string[]
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Font;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。
返回
reset()
set(properties, options)
同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。
set(properties: Interfaces.FontUpdateData, options?: OfficeExtension.UpdateOptions): void;
参数
- properties
- Word.Interfaces.FontUpdateData
一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。
- options
- OfficeExtension.UpdateOptions
提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。
返回
void
set(properties)
setAsTemplateDefault()
将指定的字体格式设置为活动文档和所有基于活动模板创建的新文档的默认格式。
setAsTemplateDefault(): void;
返回
void
注解
toJSON()
重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。
JSON.stringify
(,依次调用toJSON传递给它的 对象的 方法。) 虽然原始Word.Font对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.FontData) ,其中包含从原始对象加载的任何子属性的浅表副本。
toJSON(): Word.Interfaces.FontData;
返回
track()
根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 .sync 调用和“.run”批处理的顺序执行外部使用此对象,并在设置属性或调用对象方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将该对象添加到跟踪的对象集合。 如果此对象是集合的一部分,则还应跟踪父集合。
track(): Word.Font;
返回
untrack()
释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用 context.sync() 。
untrack(): Word.Font;