FormatCondition

FormatCondition class

Represents conditional formatting condition.

class FormatCondition;

Example

const { Workbook, CellArea, FormatConditionType, OperatorType, Color, SaveFormat } = AsposeCells;

//Instantiating a Workbook object
var workbook = new Workbook();
var sheet = workbook.worksheets.get(0);

//Adds an empty conditional formatting
var index = sheet.conditionalFormattings.add();
var fcs = sheet.conditionalFormattings.get(index);

//Sets the conditional format range.
var ca = new CellArea();
ca.startRow = 0;
ca.endRow = 0;
ca.startColumn = 0;
ca.endColumn = 0;
fcs.addArea(ca);

ca = new CellArea();
ca.startRow = 1;
ca.endRow = 1;
ca.startColumn = 1;
ca.endColumn = 1;
fcs.addArea(ca);

//Adds condition.
var conditionIndex = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
//Adds condition.
var conditionIndex2 = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");

//Sets the background color.
var fc = fcs.get(conditionIndex);
fc.style.backgroundColor = Color.Red;

//Saving the Excel file
var uint8Array = workbook.save(SaveFormat.Xlsx);

Properties

PropertyTypeDescription
formula1stringGets and sets the value or expression associated with conditional formatting.
formula2stringGets and sets the value or expression associated with conditional formatting.
operatorOperatorTypeGets and sets the conditional format operator type.
stopIfTruebooleanTrue, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;
prioritynumberThe priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where ‘1’ is the highest priority.
styleStyleGets or setts style of conditional formatted cell ranges.
typeFormatConditionTypeGets and sets whether the conditional format Type.
iconSetIconSetReadonly. Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet.
dataBarDataBarReadonly. Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar.
colorScaleColorScaleReadonly. Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale.
top10Top10Readonly. Get the conditional formatting’s “Top10” instance. The default instance’s rule highlights cells whose values fall in the top 10 bracket. Valid only for type is Top10.
aboveAverageAboveAverageReadonly. Get the conditional formatting’s “AboveAverage” instance. The default instance’s rule highlights cells that are above the average for all values in the range. Valid only for type = AboveAverage.
textstringThe text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.
timePeriodTimePeriodTypeThe applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.

Methods

MethodDescription
getFormula1(boolean, boolean)Gets the value or expression associated with this format condition.
getFormula1(boolean, boolean, number, number)Gets the value or expression of the conditional formatting of the cell.
getFormula1(number, number)Gets the formula of the conditional formatting of the cell.
getFormula2(boolean, boolean)Gets the value or expression associated with this format condition.
getFormula2(boolean, boolean, number, number)Gets the value or expression of the conditional formatting of the cell.
getFormula2(number, number)Gets the formula of the conditional formatting of the cell.
setFormulas(string, string, boolean, boolean)Sets the value or expression associated with this format condition.
setFormula1(string, boolean, boolean)Sets the value or expression associated with this format condition.
setFormula2(string, boolean, boolean)Sets the value or expression associated with this format condition.

formula1

Gets and sets the value or expression associated with conditional formatting.

formula1 : string;

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.

formula2

Gets and sets the value or expression associated with conditional formatting.

formula2 : string;

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.

operator

Gets and sets the conditional format operator type.

operator : OperatorType;

stopIfTrue

True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;

stopIfTrue : boolean;

priority

The priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where ‘1’ is the highest priority.

priority : number;

style

Gets or setts style of conditional formatted cell ranges.

style : Style;

type

Gets and sets whether the conditional format Type.

type : FormatConditionType;

iconSet

Readonly. Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet.

iconSet : IconSet;

dataBar

Readonly. Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar.

dataBar : DataBar;

colorScale

Readonly. Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale.

colorScale : ColorScale;

top10

Readonly. Get the conditional formatting’s “Top10” instance. The default instance’s rule highlights cells whose values fall in the top 10 bracket. Valid only for type is Top10.

top10 : Top10;

aboveAverage

Readonly. Get the conditional formatting’s “AboveAverage” instance. The default instance’s rule highlights cells that are above the average for all values in the range. Valid only for type = AboveAverage.

aboveAverage : AboveAverage;

text

The text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.

text : string;

timePeriod

The applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.

timePeriod : TimePeriodType;

getFormula1(boolean, boolean)

Gets the value or expression associated with this format condition.

getFormula1(isR1C1: boolean, isLocal: boolean) : string;

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.

Returns

The value or expression associated with this format condition.

getFormula1(boolean, boolean, number, number)

Gets the value or expression of the conditional formatting of the cell.

getFormula1(isR1C1: boolean, isLocal: boolean, row: number, column: number) : string;

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.
rownumberThe row index.
columnnumberThe column index.

Returns

The value or expression associated with the conditional formatting of the cell.

Remarks

The given cell must be contained by this conditional formatting, otherwise null will be returned.

getFormula1(number, number)

Gets the formula of the conditional formatting of the cell.

getFormula1(row: number, column: number) : string;

Parameters:

ParameterTypeDescription
rownumberThe row index.
columnnumberThe column index.

Returns

The formula.

getFormula2(boolean, boolean)

Gets the value or expression associated with this format condition.

getFormula2(isR1C1: boolean, isLocal: boolean) : string;

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.

Returns

The value or expression associated with this format condition.

getFormula2(boolean, boolean, number, number)

Gets the value or expression of the conditional formatting of the cell.

getFormula2(isR1C1: boolean, isLocal: boolean, row: number, column: number) : string;

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.
rownumberThe row index.
columnnumberThe column index.

Returns

The value or expression associated with the conditional formatting of the cell.

Remarks

The given cell must be contained by this conditional formatting, otherwise null will be returned.

getFormula2(number, number)

Gets the formula of the conditional formatting of the cell.

getFormula2(row: number, column: number) : string;

Parameters:

ParameterTypeDescription
rownumberThe row index.
columnnumberThe column index.

Returns

The formula.

setFormulas(string, string, boolean, boolean)

Sets the value or expression associated with this format condition.

setFormulas(formula1: string, formula2: string, isR1C1: boolean, isLocal: boolean) : void;

Parameters:

ParameterTypeDescription
formula1stringThe value or expression associated with this format condition. /// If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). /// For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.
formula2stringThe value or expression associated with this format condition. The input format is same with formula1
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.

setFormula1(string, boolean, boolean)

Sets the value or expression associated with this format condition.

setFormula1(formula: string, isR1C1: boolean, isLocal: boolean) : void;

Parameters:

ParameterTypeDescription
formulastringThe value or expression associated with this format condition. /// If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). /// For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.

setFormula2(string, boolean, boolean)

Sets the value or expression associated with this format condition.

setFormula2(formula: string, isR1C1: boolean, isLocal: boolean) : void;

Parameters:

ParameterTypeDescription
formulastringThe value or expression associated with this format condition. /// If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). /// For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.