FormatConditionCollection

FormatConditionCollection class

Represents conditional formatting. The FormatConditions can contain up to three conditional formats.

class FormatConditionCollection;

Example

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

//Adds an empty conditional formatting
var workbook = new Workbook();
var sheet = workbook.getWorksheets().get(0);
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/FormatConditionCollection.xls");

Methods

MethodDescription
get(number)Gets the formatting condition by index.
getCount()Gets the count of the conditions.
getRangeCount()Gets count of conditionally formatted ranges.
add(CellArea, FormatConditionType, OperatorType, string, string)Adds a formatting condition and effected cell rang to the FormatConditions The FormatConditions can contain up to three conditional formats. References to the other sheets are not allowed in the formulas of conditional formatting.
addArea(CellArea)Adds a conditional formatted cell range.
addCondition(FormatConditionType, OperatorType, string, string)Adds a formatting condition.
addCondition(FormatConditionType)Add a format condition.
getCellArea(number)Gets the conditional formatted cell range by index.
removeArea(number)Removes conditional formatted cell range by index.
removeArea(number, number, number, number)Remove conditional formatting int the range.
removeCondition(number)Removes the formatting condition by index.
isNull()Checks whether the implementation object is null.

get(number)

Gets the formatting condition by index.

get(index: number) : FormatCondition;

Parameters:

ParameterTypeDescription
indexnumberthe index of the formatting condition to return.

Returns

the formatting condition

getCount()

Gets the count of the conditions.

getCount() : number;

getRangeCount()

Gets count of conditionally formatted ranges.

getRangeCount() : number;

add(CellArea, FormatConditionType, OperatorType, string, string)

Adds a formatting condition and effected cell rang to the FormatConditions The FormatConditions can contain up to three conditional formats. References to the other sheets are not allowed in the formulas of conditional formatting.

add(cellArea: CellArea, type: FormatConditionType, operatorType: OperatorType, formula1: string, formula2: string) : number[];

Parameters:

ParameterTypeDescription
cellAreaCellAreaConditional formatted cell range.
typeFormatConditionTypeType of conditional formatting.It could be one of the members of FormatConditionType.
operatorTypeOperatorTypeComparison operator.It could be one of the members of OperatorType.
formula1stringThe value or expression associated with conditional formatting.
formula2stringThe value or expression associated with conditional formatting

Returns

[0]:Formatting condition object index;[1] Effected cell rang index.

addArea(CellArea)

Adds a conditional formatted cell range.

addArea(cellArea: CellArea) : number;

Parameters:

ParameterTypeDescription
cellAreaCellAreaConditional formatted cell range.

Returns

Conditional formatted cell rang index.

addCondition(FormatConditionType, OperatorType, string, string)

Adds a formatting condition.

addCondition(type: FormatConditionType, operatorType: OperatorType, formula1: string, formula2: string) : number;

Parameters:

ParameterTypeDescription
typeFormatConditionTypeThe type of format condition.
operatorTypeOperatorTypeThe operator type
formula1stringThe value or expression associated with conditional formatting. /// 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 conditional formatting. /// The input format is same with formula1

Returns

Formatting condition object index;

addCondition(FormatConditionType)

Add a format condition.

addCondition(type: FormatConditionType) : number;

Parameters:

ParameterTypeDescription
typeFormatConditionTypeFormat condition type.

Returns

Formatting condition object index;

getCellArea(number)

Gets the conditional formatted cell range by index.

getCellArea(index: number) : CellArea;

Parameters:

ParameterTypeDescription
indexnumberthe index of the conditional formatted cell range.

Returns

the conditional formatted cell range

removeArea(number)

Removes conditional formatted cell range by index.

removeArea(index: number) : void;

Parameters:

ParameterTypeDescription
indexnumberThe index of the conditional formatted cell range to be removed.

removeArea(number, number, number, number)

Remove conditional formatting int the range.

removeArea(startRow: number, startColumn: number, totalRows: number, totalColumns: number) : boolean;

Parameters:

ParameterTypeDescription
startRownumberThe startRow of the range.
startColumnnumberThe startColumn of the range.
totalRowsnumberThe number of rows of the range.
totalColumnsnumberThe number of columns of the range.

Returns

Returns TRUE, this FormatCondtionCollection should be removed.

removeCondition(number)

Removes the formatting condition by index.

removeCondition(index: number) : void;

Parameters:

ParameterTypeDescription
indexnumberThe index of the formatting condition to be removed.

isNull()

Checks whether the implementation object is null.

isNull() : boolean;