# GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase

## Content

# Class: ConditionRuleBase

[Sheets](../modules/GC.Spread.Sheets).[ConditionalFormatting](../modules/GC.Spread.Sheets.ConditionalFormatting).ConditionRuleBase

## Hierarchy

- **`ConditionRuleBase`**

  ↳ [`NormalConditionRule`](GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule)

  ↳ [`ScaleRule`](GC.Spread.Sheets.ConditionalFormatting.ScaleRule)

  ↳ [`StateRule`](GC.Spread.Sheets.ConditionalFormatting.StateRule)

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#constructor)

### Methods

- [condition](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#condition)
- [contains](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#contains)
- [createCondition](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#createcondition)
- [evaluate](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#evaluate)
- [getExpected](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#getexpected)
- [intersects](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#intersects)
- [isScaleRule](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#isscalerule)
- [priority](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#priority)
- [ranges](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#ranges)
- [reset](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#reset)
- [ruleType](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#ruletype)
- [stopIfTrue](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#stopiftrue)
- [style](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#style)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new ConditionRuleBase**(`ruleType`, `style`, `ranges`)

Represents a formatting base rule class as the specified style.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ruleType` | [`RuleType`](../enums/GC.Spread.Sheets.ConditionalFormatting.RuleType) | The type of condition formatting rule. |
| `style` | [`Style`](GC.Spread.Sheets.Style) | The style for the rule. |
| `ranges` | [`Range`](GC.Spread.Sheets.Range)[] | The range array. |

## Methods

### <a id="condition" name="condition"></a> condition

▸ **condition**(`value?`): `any`

Gets or sets the base condition of the rule.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | [`Condition`](GC.Spread.Sheets.ConditionalFormatting.Condition) | The base condition of the rule. |

#### Returns

`any`

If no value is set, returns the base condition of the rule; otherwise, returns the condition rule.

___

### <a id="contains" name="contains"></a> contains

▸ **contains**(`row`, `column`): `boolean`

Determines whether the range of cells contains the cell at the specified row and column.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `row` | `number` | The row index. |
| `column` | `number` | The column index. |

#### Returns

`boolean`

`true` if the range of cells contains the cell at the specified row and column; otherwise, `false`.

___

### <a id="createcondition" name="createcondition"></a> createCondition

▸ **createCondition**(): [`Condition`](GC.Spread.Sheets.ConditionalFormatting.Condition)

Creates condition for the rule.

**`example`**
```javascript
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.formulaRule);
rule.formula("=A1=B1+C1");
var condition = rule.createCondition();
console.log(condition.evaluate(activeSheet));
```

#### Returns

[`Condition`](GC.Spread.Sheets.ConditionalFormatting.Condition)

The condition.

___

### <a id="evaluate" name="evaluate"></a> evaluate

▸ **evaluate**(`evaluator`, `baseRow`, `baseColumn`, `actual`): [`Style`](GC.Spread.Sheets.Style)

Returns the cell style of the rule if the cell satisfies the condition.

**`example`**
```javascript
 activeSheet.setValue(0, 0, 1, 3);
 activeSheet.setValue(1, 0, 15, 3);
 activeSheet.setValue(2, 0, 25, 3);
 activeSheet.setValue(3, 0, -1, 3);
 var iconSetRule = new GC.Spread.Sheets.ConditionalFormatting.IconSetRule();
 iconSetRule.ranges([new GC.Spread.Sheets.Range(0, 0, 4, 1)]);
 iconSetRule.iconSetType(GC.Spread.Sheets.ConditionalFormatting.IconSetType.fourTrafficLights);
 activeSheet.conditionalFormats.addRule(iconSetRule);
 for (var i = 1; i < 5; i++) {
     var evaluateResult = iconSetRule.evaluate(activeSheet, i, 0, activeSheet.getValue(i, 0));
     console.log(evaluateResult);
 }
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `evaluator` | `Object` | The object that can evaluate a condition. |
| `baseRow` | `number` | The row index. |
| `baseColumn` | `number` | The column index. |
| `actual` | `Object` | The actual value. |

#### Returns

[`Style`](GC.Spread.Sheets.Style)

The cell style of the rule.

___

### <a id="getexpected" name="getexpected"></a> getExpected

▸ **getExpected**(): [`Style`](GC.Spread.Sheets.Style)

Gets the style of the base rule.

**`example`**
```javascript
 //This example uses the getExpected method.
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10;i++){
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 console.log(condition.getExpected());
```

#### Returns

[`Style`](GC.Spread.Sheets.Style)

___

### <a id="intersects" name="intersects"></a> intersects

▸ **intersects**(`row`, `column`, `rowCount`, `columnCount`): `boolean`

Specifies whether the range for this rule intersects another range.

**`example`**
```javascript
 //This example uses the intersects method.
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10; i++) {
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 activeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function(e, info) {
     var selection = info.newSelections[0];
     var result = condition.intersects(selection.row, selection.col, selection.rowCount, selection.colCount);
     if (result) {
         alert("current selection is intersects with condition formatting range");
     } else {
         alert("current selection is not intersects with condition formatting range");
     }
 });
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `row` | `number` | The row index. |
| `column` | `number` | The column index. |
| `rowCount` | `number` | The number of rows. |
| `columnCount` | `number` | The number of columns. |

#### Returns

`boolean`

`true` if the range for this rule intersects another range; otherwise, `false`.

___

### <a id="isscalerule" name="isscalerule"></a> isScaleRule

▸ **isScaleRule**(): `boolean`

Specifies whether this rule is a scale rule.

#### Returns

`boolean`

`true` if this rule is a scale rule; otherwise, `false`.

___

### <a id="priority" name="priority"></a> priority

▸ **priority**(`value?`): `any`

Gets or sets the priority of the rule.

**`example`**
```javascript
// Example: Create multiple rules with different priorities
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
rule.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
rule.value1(10);
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
rule.style(style);
rule.priority(1); // Set priority to 1 (highest priority)
activeSheet.conditionalFormats.addRule(rule);
var style2 = new GC.Spread.Sheets.Style();
style2.backColor = "blue";
var rule2 = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule2.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
rule2.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
rule2.value1(100);
rule2.ranges([new GC.Spread.Sheets.Range(5, 0, 10, 1)]);
rule2.style(style2);
rule2.priority(2); // Set priority to 1 (highest priority)
activeSheet.conditionalFormats.addRule(rule2);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | `number` | The priority of the rule. |

#### Returns

`any`

If no value is set, returns the priority of the rule; otherwise, returns the condition rule.

___

### <a id="ranges" name="ranges"></a> ranges

▸ **ranges**(`value?`): `any`

Gets or sets the condition rule ranges.

**`example`**
```javascript
var style = new GC.Spread.Sheets.Style();
style.backColor = "green";
var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
activeSheet.conditionalFormats.addUniqueRule(style, ranges);
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 50);
activeSheet.setValue(2, 0, 11);
activeSheet.setValue(3, 0, 5);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | [`Range`](GC.Spread.Sheets.Range)[] | The condition rule ranges. |

#### Returns

`any`

If no value is set, returns a copy of the condition rule ranges; otherwise, returns the condition rule.

___

### <a id="reset" name="reset"></a> reset

▸ **reset**(): `void`

Resets the rule.

**`example`**
```javascript
 activeSheet.setArray(0, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "red";
 style.foreColor = "black";
 var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
 cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
 cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
 cell.value1(2);
 cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
 cell.style(style);
 activeSheet.conditionalFormats.addRule(cell);
 var style = new GC.Spread.Sheets.Style();
 style.cellButtons = [{
     caption: "Reset",
     useButtonStyle: true,
     width: 60,
     command: function(sheet) {
         cell.reset();
         sheet.resumePaint();
     }
 }];
 activeSheet.setStyle(16, 4, style);
```

#### Returns

`void`

___

### <a id="ruletype" name="ruletype"></a> ruleType

▸ **ruleType**(`value?`): `any`

Gets or sets the condition rule type.

**`example`**
```javascript
//This example uses the ruleType method.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | [`RuleType`](../enums/GC.Spread.Sheets.ConditionalFormatting.RuleType) | The condition rule type. |

#### Returns

`any`

If no value is set, returns the condition rule type; otherwise, returns the condition rule.

___

### <a id="stopiftrue" name="stopiftrue"></a> stopIfTrue

▸ **stopIfTrue**(`value?`): `any`

Gets or sets whether rules with lower priority are applied before this rule.

**`example`**
```javascript
//This example applies multiple rules.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | `boolean` | Whether rules with lower priority are applied before this rule. |

#### Returns

`any`

If no value is set, returns whether the rules with lower priority are not applied before this rule; otherwise, returns the condition rule.

___

### <a id="style" name="style"></a> style

▸ **style**(`value?`): `any`

Gets or sets the style for the rule.

**`example`**
```javascript
//This example applies multiple rules.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | [`Style`](GC.Spread.Sheets.Style) | The style for the rule. |

#### Returns

`any`

If no value is set, returns the style for the rule; otherwise, returns the condition rule.
