ConditionalFormatRule

Access conditional formatting rules. To create a new rule, use `https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#newConditionalFormatRule()` and `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder`.
You can use `https://developers.google.com/apps-script/reference/spreadsheet/sheet#setConditionalFormatRules(ConditionalFormatRule)` to set the
rules for a given sheet.

For rules that use boolean condition criteria, you can access the formatting settings by
calling `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule#getBooleanCondition()` and using the methods on the returned `https://developers.google.com/apps-script/reference/spreadsheet/boolean-condition` object.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule#copy()` | `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder` | Returns a rule builder preset with this rule's settings. |
| `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule#getBooleanCondition()` | `https://developers.google.com/apps-script/reference/spreadsheet/boolean-condition|null` | Retrieves the rule's `https://developers.google.com/apps-script/reference/spreadsheet/boolean-condition` information if this rule uses boolean condition criteria. |
| `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule#getGradientCondition()` | `https://developers.google.com/apps-script/reference/spreadsheet/gradient-condition|null` | Retrieves the rule's `https://developers.google.com/apps-script/reference/spreadsheet/gradient-condition` information, if this rule uses gradient condition criteria. |
| `https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule#getRanges()` | `https://developers.google.com/apps-script/reference/spreadsheet/range` | Retrieves the ranges to which this conditional format rule is applied. |

## Detailed documentation

### `copy()`

Returns a rule builder preset with this rule's settings.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder` --- A builder based on this rule's settings.

*** ** * ** ***

### `getBooleanCondition()`

Retrieves the rule's `https://developers.google.com/apps-script/reference/spreadsheet/boolean-condition` information if this rule uses
boolean condition criteria. Otherwise returns `null`. Boolean conditions contain
formatting settings such as font weight, font color, and background color.

```javascript
// Log the boolean criteria type of the first conditional format rules of a
// sheet.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const booleanCondition = rule.getBooleanCondition();
if (booleanCondition != null) {
  Logger.log(booleanCondition.getCriteriaType());
}
```

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/boolean-condition|null` --- The boolean condition object, or `null` if the rule does not use a boolean
condition.

*** ** * ** ***

### `getGradientCondition()`

Retrieves the rule's `https://developers.google.com/apps-script/reference/spreadsheet/gradient-condition` information, if this rule
uses gradient condition criteria. Otherwise returns `null`.

```javascript
// Log the gradient minimum color of the first conditional format rule of a
// sheet.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const gradientCondition = rule.getGradientCondition();
if (gradientCondition != null) {
  // Assume the color has ColorType.RGB.
  Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString());
}
```

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/gradient-condition|null` --- The gradient condition object, or `null` if the rule does not use a gradient
condition.

*** ** * ** ***

### `getRanges()`

Retrieves the ranges to which this conditional format rule is applied.

```javascript
// Log each range of the first conditional format rule of a sheet.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const ranges = rule.getRanges();
for (let i = 0; i < ranges.length; i++) {
  Logger.log(ranges[i].getA1Notation());
}
```

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/range` --- The ranges to which this conditional format rule is applied.