# GC.Spread.Sheets.ConditionalFormatting.StateRule

## Content

# Class: StateRule

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

## Hierarchy

- [`ConditionRuleBase`](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase)

  ↳ **`StateRule`**

## Table of contents

### Constructors

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

### Methods

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

## Constructors

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

• **new StateRule**(`ruleType`, `state`, `style?`, `ranges?`)

Represents a state rule.

**`example`**
```
// add a row state rule with red back color in whole sheet
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var stateRule = new GC.Spread.Sheets.ConditionalFormatting.StateRule(GC.Spread.Sheets.ConditionalFormatting.RuleType.rowStateRule, style, [new GC.Spread.Sheets.Range(-1, -1, -1, -1)]);
activeSheet.conditionalFormats.addRule(cell);
// add a row state rule with two styles to different corresponding ranges
var stateRule = new GC.Spread.Sheets.ConditionalFormatting.StateRule(
     GC.Spread.Sheets.ConditionalFormatting.RuleType.rowStateRule,
     [new GC.Spread.Sheets.Style("green"), new GC.Spread.Sheets.Style("red")],
     [new GC.Spread.Sheets.Range(1, 1, 10, 5)\uff0c new GC.Spread.Sheets.Range(1, 7, 10, 5)]
);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ruleType` | [`RuleType`](../enums/GC.Spread.Sheets.ConditionalFormatting.RuleType) | The state rule type, it would be GC.Spread.Sheets.ConditionalFormatting.RuleType.rowStateRule or GC.Spread.Sheets.ConditionalFormatting.RuleType.columnStateRule. |
| `state` | [`RowColumnStates`](../enums/GC.Spread.Sheets.RowColumnStates) | The state. |
| `style?` | [`Style`](GC.Spread.Sheets.Style) \| [`Style`](GC.Spread.Sheets.Style)[] | The style that is applied to the cell when the state is met. It could an array of styles. |
| `ranges?` | [`Range`](GC.Spread.Sheets.Range)[] | The cell ranges where the rule is applied whose item type is GC.Spread.Sheets.Range. |

#### Overrides

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

## 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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[condition](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#condition)

___

### <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`.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[contains](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#contains)

___

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

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

Creates condition for the rule.

#### Returns

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

The condition.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[createCondition](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#createcondition)

___

### <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.

#### 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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[evaluate](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#evaluate)

___

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

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

Gets the style of the base rule.

#### Returns

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

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[getExpected](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#getexpected)

___

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

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

Specifies whether the range for this rule intersects another 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`.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[intersects](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#intersects)

___

### <a id="isrow" name="isrow"></a> isRow

▸ **isRow**(): `boolean`

Get whether this state rule will applied to row direction.

#### Returns

`boolean`

Whether this state rule will be applied to row direction, otherwise, it will be applied to column direction.

___

### <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`.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[isScaleRule](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#isscalerule)

___

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

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

Gets or sets the priority of the rule.

#### 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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[priority](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#priority)

___

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

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

Gets or sets the condition rule ranges.

**`example`**
```
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 the condition rule ranges; otherwise, returns the condition rule.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[ranges](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#ranges)

___

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

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

Resets the rule.

#### Returns

`void`

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[reset](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#reset)

___

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

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

Gets or sets the condition rule type.

**`example`**
```
//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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[ruleType](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#ruletype)

___

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

▸ **state**(`value?`): [`RowColumnStates`](../enums/GC.Spread.Sheets.RowColumnStates)

Gets or sets the rule state.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | [`RowColumnStates`](../enums/GC.Spread.Sheets.RowColumnStates) | The state. |

#### Returns

[`RowColumnStates`](../enums/GC.Spread.Sheets.RowColumnStates)

The rule state.

___

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

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

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

**`example`**
```
//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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[stopIfTrue](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#stopiftrue)

___

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

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

Gets or sets the style for the rule.

**`example`**
```
//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.

#### Inherited from

[ConditionRuleBase](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase).[style](GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase#style)
