ExcelScript.ConditionalFormatRule interface

Represents a rule, for all traditional rule/format pairings.

Remarks

Examples

/**
 * This script applies a custom conditional formatting to the selected range.
 * A light-green fill is applied to a cell if the value is larger than the value in the row's previous column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the selected cells.
  let selectedRange = workbook.getSelectedRange();

  // Apply a rule for positive change from the previous column.
  let positiveChange: ExcelScript.ConditionalFormat = selectedRange.addConditionalFormat(ExcelScript.ConditionalFormatType.custom);

  // Set the conditional format to be a lightgreen fill.
  let positiveCustom: ExcelScript.CustomConditionalFormat = positiveChange.getCustom();
  positiveCustom.getFormat().getFill().setColor("lightgreen");

  // Set the conditional rule to be if there is positive change across the row.
  let positiveRule: ExcelScript.ConditionalFormatRule = positiveCustom.getRule();
  positiveRule.setFormula(`=${selectedRange.getCell(0, 0).getAddress()}>${selectedRange.getOffsetRange(0, -1).getCell(0, 0).getAddress()}`);
}

Methods

getFormula()

The formula, if required, on which to evaluate the conditional format rule.

getFormulaLocal()

The formula, if required, on which to evaluate the conditional format rule in the user's language.

setFormula(formula)

The formula, if required, on which to evaluate the conditional format rule.

setFormulaLocal(formulaLocal)

The formula, if required, on which to evaluate the conditional format rule in the user's language.

Method Details

getFormula()

The formula, if required, on which to evaluate the conditional format rule.

getFormula(): string;

Returns

string

getFormulaLocal()

The formula, if required, on which to evaluate the conditional format rule in the user's language.

getFormulaLocal(): string;

Returns

string

setFormula(formula)

The formula, if required, on which to evaluate the conditional format rule.

setFormula(formula: string): void;

Parameters

formula

string

Returns

void

setFormulaLocal(formulaLocal)

The formula, if required, on which to evaluate the conditional format rule in the user's language.

setFormulaLocal(formulaLocal: string): void;

Parameters

formulaLocal

string

Returns

void