Font
This topic describes the APIs for the Font object in text documents.
Font
ActiveDocument.Range(Start, End).Font
Retrieves a font object.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Fontor
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; }
Properties
ActiveDocument.Range(Start, End).Font.Color
Use the Color property to set the color of a font object. The color can be a value created by the RGB function.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Font.Coloror
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; // Set the color of the font. font.Color = '#228B22'; }
ActiveDocument.Range(Start, End).Font.ColorIndex
Use the ColorIndex property to set the color of a font object. The color can be a value from WdColorIndex.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Font.ColorIndex = WdColorIndexor
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; // Set the color of the font. font.ColorIndex = 2; }
ActiveDocument.Range(Start, End).Font.HighLight
Use the HighLight property to set the highlight color of a font object.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Font.HighLightor
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; // Set the highlight color of the font. font.HighLight = '#228B22'; }
ActiveDocument.Range(Start, End).Font.Name
You can use the Name property to set the font type.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Font.Nameor
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; // Set the type of the font. font.Name = 'SimSun'; }
ActiveDocument.Range(Start, End).Font.Size
Use the Size property to set the size of a font object.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Range(Start, End).Font.Sizeor
expression.ActiveDocument.ActiveWindow.Selection.Fontexpression: The application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the font object. const font = await app.ActiveDocument.Range(0, 20).Font; // Set the size of the font. font.Size = 30; }
ActiveDocument.Selection.Font.Underline
Use the Underline property to set or retrieve the underline type of the selected content.
Syntax
expression.ActiveDocument.Selection.Font.Underlineexpression: The application object for the document type.
Parameters
WdUnderline specifies the underline type.
Return value
Returns the underline type WdUnderline. Returns
nullif no underline exists. ReturnswdUndefinedif the selection contains multiple underline types.Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // Set the underline type to a heavy wavy line. app.ActiveDocument.Selection.Font.Underline = app.Enum.WdUnderline.wdUnderlineWavyHeavy // Get the underline type. const underlineType = await app.ActiveDocument.Selection.Font.Underline console.log('underlineType: ', underlineType) }
ActiveDocument.Selection.Font.UnderlineColor
Use the UnderlineColor property to set or retrieve the underline color of the selected content.
Syntax
expression.ActiveDocument.Selection.Font.UnderlineColorexpression: The application object for the document type.
Parameters
A hexadecimal color value, such as
'#FF0000'.Return value
The default value is
'#000000'. Returnsnullif no underline exists. ReturnswdUndefinedif the selection contains multiple colors.Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // Set the underline color to red. app.ActiveDocument.Selection.Font.UnderlineColor = '#FF0000' // Get the underline color. const underlineColor = await app.ActiveDocument.Selection.Font.UnderlineColor console.log('underlineColor: ', underlineColor) }
ActiveDocument.Selection.Font.Italic
Use the Italic property to set or determine whether the selected content is italic.
Syntax
expression.ActiveDocument.Selection.Font.Italicexpression: The application object for the document type.
Parameters
trueindicates italic andfalseindicates not italic.Return value
truefor italic,falsefor non-italic, and wdUndefined for mixed formatting.Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // Set the content to italic. app.ActiveDocument.Selection.Font.Italic = true // Check whether the content is italic. const italic = await app.ActiveDocument.Selection.Font.Italic console.log('italic: ', italic) }
ActiveDocument.Selection.Font.Bold
Use the Bold property to set or determine whether the selected content is bold.
Syntax
expression.ActiveDocument.Selection.Font.Boldexpression: The application object for the document type.
Parameters
trueindicates bold andfalseindicates not bold.Return value
A value of
trueindicates that the text is bold,falseindicates that the text is not bold, andwdUndefinedindicates that the text has mixed formatting.Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // Set the content to bold. app.ActiveDocument.Selection.Font.Bold = true // Check whether the content is bold. const bold = await app.ActiveDocument.Selection.Font.Bold console.log('bold: ', bold) }