FormatCondition

FormatCondition class

Represents conditional formatting condition.

class FormatCondition;

Example

const { Workbook, CellArea, FormatConditionType, OperatorType, Color } = require("aspose.cells.node");

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

//Adds an empty conditional formatting
var index = sheet.getConditionalFormattings().add();
var fcs = sheet.getConditionalFormattings().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.getStyle().setBackgroundColor(Color.Red);

//Saving the Excel file
workbook.save("output/FormatCondition.xls");

Methods

MethodDescription
getFormula1()Gets and sets the value or expression associated with conditional formatting.
setFormula1(string)Gets and sets the value or expression associated with conditional formatting.
getFormula2()Gets and sets the value or expression associated with conditional formatting.
setFormula2(string)Gets and sets the value or expression associated with conditional formatting.
getOperator()Gets and sets the conditional format operator type.
setOperator(OperatorType)Gets and sets the conditional format operator type.
getStopIfTrue()True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;
setStopIfTrue(boolean)True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;
getPriority()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.
setPriority(number)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.
getStyle()Gets or setts style of conditional formatted cell ranges.
setStyle(Style)Gets or setts style of conditional formatted cell ranges.
getType()Gets and sets whether the conditional format Type.
setType(FormatConditionType)Gets and sets whether the conditional format Type.
getIconSet()Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet.
getDataBar()Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar.
getColorScale()Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale.
getTop10()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.
getAboveAverage()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.
getText()The text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.
setText(string)The text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.
getTimePeriod()The applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.
setTimePeriod(TimePeriodType)The applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.
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.
isNull()Checks whether the implementation object is null.

getFormula1()

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

getFormula1() : 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: “="=…"”.

setFormula1(string)

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

setFormula1(value: string) : void;

Parameters:

ParameterTypeDescription
valuestringThe value to set.

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: “="=…"”.

getFormula2()

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

getFormula2() : 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: “="=…"”.

setFormula2(string)

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

setFormula2(value: string) : void;

Parameters:

ParameterTypeDescription
valuestringThe value to set.

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: “="=…"”.

getOperator()

Gets and sets the conditional format operator type.

getOperator() : OperatorType;

Returns

OperatorType

setOperator(OperatorType)

Gets and sets the conditional format operator type.

setOperator(value: OperatorType) : void;

Parameters:

ParameterTypeDescription
valueOperatorTypeThe value to set.

getStopIfTrue()

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

getStopIfTrue() : boolean;

setStopIfTrue(boolean)

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

setStopIfTrue(value: boolean) : void;

Parameters:

ParameterTypeDescription
valuebooleanThe value to set.

getPriority()

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.

getPriority() : number;

setPriority(number)

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.

setPriority(value: number) : void;

Parameters:

ParameterTypeDescription
valuenumberThe value to set.

getStyle()

Gets or setts style of conditional formatted cell ranges.

getStyle() : Style;

Returns

Style

setStyle(Style)

Gets or setts style of conditional formatted cell ranges.

setStyle(value: Style) : void;

Parameters:

ParameterTypeDescription
valueStyleThe value to set.

getType()

Gets and sets whether the conditional format Type.

getType() : FormatConditionType;

Returns

FormatConditionType

setType(FormatConditionType)

Gets and sets whether the conditional format Type.

setType(value: FormatConditionType) : void;

Parameters:

ParameterTypeDescription
valueFormatConditionTypeThe value to set.

getIconSet()

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

getIconSet() : IconSet;

Returns

IconSet

getDataBar()

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

getDataBar() : DataBar;

Returns

DataBar

getColorScale()

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

getColorScale() : ColorScale;

Returns

ColorScale

getTop10()

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.

getTop10() : Top10;

Returns

Top10

getAboveAverage()

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.

getAboveAverage() : AboveAverage;

Returns

AboveAverage

getText()

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

getText() : string;

setText(string)

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

setText(value: string) : void;

Parameters:

ParameterTypeDescription
valuestringThe value to set.

getTimePeriod()

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

getTimePeriod() : TimePeriodType;

Returns

TimePeriodType

setTimePeriod(TimePeriodType)

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

setTimePeriod(value: TimePeriodType) : void;

Parameters:

ParameterTypeDescription
valueTimePeriodTypeThe value to set.

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.

isNull()

Checks whether the implementation object is null.

isNull() : boolean;