Excel.Style class

An object encapsulating a style's format and other properties.

[ API set: ExcelApi 1.7 ]

Extends
OfficeExtension.ClientObject

Properties

autoIndent

Indicates if text is automatically indented when the text alignment in a cell is set to equal distribution.

[ API set: ExcelApi 1.8 ]

borders

A Border collection of four Border objects that represent the style of the four borders.

[ API set: ExcelApi 1.7 ]

builtIn

Indicates if the style is a built-in style.

[ API set: ExcelApi 1.7 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

fill

The Fill of the style.

[ API set: ExcelApi 1.7 ]

font

A Font object that represents the font of the style.

[ API set: ExcelApi 1.7 ]

formulaHidden

Indicates if the formula will be hidden when the worksheet is protected.

[ API set: ExcelApi 1.7 ]

horizontalAlignment

Represents the horizontal alignment for the style. See Excel.HorizontalAlignment for details.

[ API set: ExcelApi 1.7 ]

includeAlignment

Indicates if the style includes the AutoIndent, HorizontalAlignment, VerticalAlignment, WrapText, IndentLevel, and TextOrientation properties.

[ API set: ExcelApi 1.7 ]

includeBorder

Indicates if the style includes the Color, ColorIndex, LineStyle, and Weight border properties.

[ API set: ExcelApi 1.7 ]

includeFont

Indicates if the style includes the Background, Bold, Color, ColorIndex, FontStyle, Italic, Name, Size, Strikethrough, Subscript, Superscript, and Underline font properties.

[ API set: ExcelApi 1.7 ]

includeNumber

Indicates if the style includes the NumberFormat property.

[ API set: ExcelApi 1.7 ]

includePatterns

Indicates if the style includes the Color, ColorIndex, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.

[ API set: ExcelApi 1.7 ]

includeProtection

Indicates if the style includes the FormulaHidden and Locked protection properties.

[ API set: ExcelApi 1.7 ]

indentLevel

An integer from 0 to 250 that indicates the indent level for the style.

[ API set: ExcelApi 1.7 ]

locked

Indicates if the object is locked when the worksheet is protected.

[ API set: ExcelApi 1.7 ]

name

The name of the style.

[ API set: ExcelApi 1.7 ]

numberFormat

The format code of the number format for the style.

[ API set: ExcelApi 1.7 ]

numberFormatLocal

The localized format code of the number format for the style.

[ API set: ExcelApi 1.7 ]

readingOrder

The reading order for the style.

[ API set: ExcelApi 1.7 ]

shrinkToFit

Indicates if text automatically shrinks to fit in the available column width.

[ API set: ExcelApi 1.7 ]

textOrientation

The text orientation for the style.

[ API set: ExcelApi 1.8 ]

verticalAlignment

Represents the vertical alignment for the style. See Excel.VerticalAlignment for details.

[ API set: ExcelApi 1.7 ]

wrapText

Indicates if Microsoft Excel wraps the text in the object.

[ API set: ExcelApi 1.7 ]

Methods

delete()

Deletes this style.

[ API set: ExcelApi 1.7 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Style object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.StyleData) that contains shallow copies of any loaded child properties from the original object.

Property Details

autoIndent

Indicates if text is automatically indented when the text alignment in a cell is set to equal distribution.

[ API set: ExcelApi 1.8 ]

autoIndent: boolean;

Property Value

boolean

borders

A Border collection of four Border objects that represent the style of the four borders.

[ API set: ExcelApi 1.7 ]

readonly borders: Excel.RangeBorderCollection;

Property Value

builtIn

Indicates if the style is a built-in style.

[ API set: ExcelApi 1.7 ]

readonly builtIn: boolean;

Property Value

boolean

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

fill

The Fill of the style.

[ API set: ExcelApi 1.7 ]

readonly fill: Excel.RangeFill;

Property Value

font

A Font object that represents the font of the style.

[ API set: ExcelApi 1.7 ]

readonly font: Excel.RangeFont;

Property Value

Examples

await Excel.run(async (context) => {
    let style = context.workbook.styles.getItem("Normal");
    style.font.load("bold, color, italic, name, size");
    style.fill.load("color");

    await context.sync();

    console.log("Bold: " + style.font.bold);
    console.log("Font color: " + style.font.color);
    console.log("Italic: " + style.font.italic);
    console.log("Name: " + style.font.name);
    console.log("Size: " + style.font.size);
    console.log("Fill color: " + style.fill.color);
});

formulaHidden

Indicates if the formula will be hidden when the worksheet is protected.

[ API set: ExcelApi 1.7 ]

formulaHidden: boolean;

Property Value

boolean

horizontalAlignment

Represents the horizontal alignment for the style. See Excel.HorizontalAlignment for details.

[ API set: ExcelApi 1.7 ]

horizontalAlignment: Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed";

Property Value

Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed"

Examples

await Excel.run(async (context) => {
    let worksheet = context.workbook.worksheets.getItem("Sample");
    let range = worksheet.getRange("A1:E1");

    // Apply built-in style. 
    // Styles are in the Home tab ribbon.
    range.style = Excel.BuiltInStyle.neutral;
    range.format.horizontalAlignment = "Right";

    await context.sync();
});

includeAlignment

Indicates if the style includes the AutoIndent, HorizontalAlignment, VerticalAlignment, WrapText, IndentLevel, and TextOrientation properties.

[ API set: ExcelApi 1.7 ]

includeAlignment: boolean;

Property Value

boolean

includeBorder

Indicates if the style includes the Color, ColorIndex, LineStyle, and Weight border properties.

[ API set: ExcelApi 1.7 ]

includeBorder: boolean;

Property Value

boolean

includeFont

Indicates if the style includes the Background, Bold, Color, ColorIndex, FontStyle, Italic, Name, Size, Strikethrough, Subscript, Superscript, and Underline font properties.

[ API set: ExcelApi 1.7 ]

includeFont: boolean;

Property Value

boolean

includeNumber

Indicates if the style includes the NumberFormat property.

[ API set: ExcelApi 1.7 ]

includeNumber: boolean;

Property Value

boolean

includePatterns

Indicates if the style includes the Color, ColorIndex, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.

[ API set: ExcelApi 1.7 ]

includePatterns: boolean;

Property Value

boolean

includeProtection

Indicates if the style includes the FormulaHidden and Locked protection properties.

[ API set: ExcelApi 1.7 ]

includeProtection: boolean;

Property Value

boolean

indentLevel

An integer from 0 to 250 that indicates the indent level for the style.

[ API set: ExcelApi 1.7 ]

indentLevel: number;

Property Value

number

locked

Indicates if the object is locked when the worksheet is protected.

[ API set: ExcelApi 1.7 ]

locked: boolean;

Property Value

boolean

name

The name of the style.

[ API set: ExcelApi 1.7 ]

readonly name: string;

Property Value

string

numberFormat

The format code of the number format for the style.

[ API set: ExcelApi 1.7 ]

numberFormat: string;

Property Value

string

numberFormatLocal

The localized format code of the number format for the style.

[ API set: ExcelApi 1.7 ]

numberFormatLocal: string;

Property Value

string

readingOrder

The reading order for the style.

[ API set: ExcelApi 1.7 ]

readingOrder: Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft";

Property Value

Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft"

shrinkToFit

Indicates if text automatically shrinks to fit in the available column width.

[ API set: ExcelApi 1.7 ]

shrinkToFit: boolean;

Property Value

boolean

textOrientation

The text orientation for the style.

[ API set: ExcelApi 1.8 ]

textOrientation: number;

Property Value

number

verticalAlignment

Represents the vertical alignment for the style. See Excel.VerticalAlignment for details.

[ API set: ExcelApi 1.7 ]

verticalAlignment: Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed";

Property Value

Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed"

wrapText

Indicates if Microsoft Excel wraps the text in the object.

[ API set: ExcelApi 1.7 ]

wrapText: boolean;

Property Value

boolean

Method Details

delete()

Deletes this style.

[ API set: ExcelApi 1.7 ]

delete(): void;

Returns

void

Examples

await Excel.run(async (context) => {
    let style = context.workbook.styles.getItem("Diagonal Orientation Style");

    // Delete the diagonal orientation style from the style collection.
    // Styles are in the Home tab ribbon.
    style.delete();

    await context.sync();

    console.log("Successfully deleted the diagonal orientation style from the Home tab ribbon.");
});

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.StyleLoadOptions): Excel.Style;

Parameters

options
Excel.Interfaces.StyleLoadOptions

Provides options for which properties of the object to load.

Returns

Examples

await Excel.run(async (context) => {
    let style = context.workbook.styles.getItem("Diagonal Orientation Style");            
    style.load("textOrientation, horizontalAlignment, autoIndent, readingOrder, wrapText, includeProtection, shrinkToFit, locked");

    await context.sync();

    console.log("Orientation: " + style.textOrientation);
    console.log("Horizontal alignment: " + style.horizontalAlignment);
    console.log("Add indent: " + style.autoIndent);
    console.log("Reading order: " + style.readingOrder);
    console.log("Wrap text: " + style.wrapText);
    console.log("Include protection: " + style.includeProtection);
    console.log("Shrink to fit: " + style.shrinkToFit);
    console.log("Style locked: " + style.locked);
});

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.Style;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.Style;

Parameters

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

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.StyleUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Interfaces.StyleUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Excel.Style): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Style): void;

Parameters

properties
Excel.Style

Returns

void

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Style object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.StyleData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.StyleData;

Returns