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
Method | Description |
---|---|
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:
Parameter | Type | Description |
---|---|---|
index | number | the 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:
Parameter | Type | Description |
---|---|---|
cellArea | CellArea | Conditional formatted cell range. |
type | FormatConditionType | Type of conditional formatting.It could be one of the members of FormatConditionType. |
operatorType | OperatorType | Comparison operator.It could be one of the members of OperatorType. |
formula1 | string | The value or expression associated with conditional formatting. |
formula2 | string | The 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:
Parameter | Type | Description |
---|---|---|
cellArea | CellArea | Conditional 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:
Parameter | Type | Description |
---|---|---|
type | FormatConditionType | The type of format condition. |
operatorType | OperatorType | The operator type |
formula1 | string | The 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: “="=…"”. |
formula2 | string | The 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:
Parameter | Type | Description |
---|---|---|
type | FormatConditionType | Format condition type. |
Returns
Formatting condition object index;
getCellArea(number)
Gets the conditional formatted cell range by index.
getCellArea(index: number) : CellArea;
Parameters:
Parameter | Type | Description |
---|---|---|
index | number | the 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:
Parameter | Type | Description |
---|---|---|
index | number | The 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:
Parameter | Type | Description |
---|---|---|
startRow | number | The startRow of the range. |
startColumn | number | The startColumn of the range. |
totalRows | number | The number of rows of the range. |
totalColumns | number | The 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:
Parameter | Type | Description |
---|---|---|
index | number | The index of the formatting condition to be removed. |
isNull()
Checks whether the implementation object is null.
isNull() : boolean;