Excel.CustomConditionalFormat class

Represents a custom conditional format type.

[ API set: ExcelApi 1.6 ]

Extends
OfficeExtension.ClientObject

Properties

format

Returns a format object, encapsulating the conditional formats font, fill, borders, and other properties. Read-only.

[ API set: ExcelApi 1.6 ]

rule

Represents the Rule object on this conditional format. Read-only.

[ API set: ExcelApi 1.6 ]

Methods

load(option)

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

toJSON()

Property Details

format

Returns a format object, encapsulating the conditional formats font, fill, borders, and other properties. Read-only.

[ API set: ExcelApi 1.6 ]

readonly format: Excel.ConditionalRangeFormat;
Property Value

Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    const range = sheet.getRange("B8:E13");
    const conditionalFormat = range.conditionalFormats.add(Excel.ConditionalFormatType.custom);
    conditionalFormat.custom.rule.formula = '=IF(B8>INDIRECT("RC[-1]",0),TRUE)';
    conditionalFormat.custom.format.font.color = "green";

    await context.sync();
});

rule

Represents the Rule object on this conditional format. Read-only.

[ API set: ExcelApi 1.6 ]

readonly rule: Excel.ConditionalFormatRule;
Property Value

Examples

Excel.run(function (ctx) {
    var sheet = ctx.workbook.worksheets.getActiveWorksheet();
    var range = sheet.getRange("A1:A5");
    range.values = [[1], [20], [""], [5], ["test"]];
    var cf = range.conditionalFormats.add(Excel.ConditionalFormatType.custom);
    var cfCustom = cf.customOrNullObject;
    cfCustom.rule.formula = "=ISBLANK(A1)";
    cfCustom.format.fill.color = "#00FF00";
    return ctx.sync().then(function () {
        console.log("Added new custom conditional format highlighting all blank cells.");
    });
}).catch(function (error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

Method Details

load(option)

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

load(option?: string | string[]): Excel.CustomConditionalFormat;
Parameters
option
string | string[]

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

Returns
Remarks

In addition to this signature, this method has the following signatures:

load(option?: { select?: string; expand?: string; }): Excel.CustomConditionalFormat - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.CustomConditionalFormat - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

toJSON()

toJSON(): Excel.Interfaces.CustomConditionalFormatData;
Returns