Conditional Formatting and Cell Styles
Data bars, color scales, icon sets and highlights are conditional formatting: they change the effective appearance of a cell when its value, or a supported formula, meets a rule. The rule is recalculated as the data changes. Conditional formatting is useful for finding exceptions, comparing values and showing progress without manually coloring each cell.
Named cell styles and workbook themes add the reusable base formatting that a rule draws on top of. The examples use the Performance worksheet of the sales sample, first in the ribbon and then in code.
What the Rules Show
The Performance sheet in the sales and dashboard sample compares six accounts:

| Visual cue | What it means in this example |
|---|---|
| Blue bars in Revenue | Longer bars identify higher revenue in B4:B9 |
| Green revenue highlights | Revenue is greater than $120,000 |
| Arrows in Progress | Green is at least 100% of target, yellow is at least 80%, red is below 80% |
| Red-to-green Margin scale | Low margins are red, intermediate margins yellow and high margins green within this range |
The values and formulas remain in the cells. Progress is Revenue divided by Target. The visual rules help a reader identify Northstar's high revenue and Pacific's low margin without changing either amount.
Pick a Rule From the Home Ribbon
- Select the cells the rule should evaluate, such as
B4:B9. - Open Home → Conditional Formatting. If the ribbon is narrow, open the Styles group first.
- Choose a value rule, data bar, color scale or icon set appropriate to the data.
- Review its settings and apply it to the selection.

The menu groups the rules by what they show:
- Highlight Cells Rules identifies values matching a criterion.
- Top/Bottom Rules identifies relative extremes.
- Data Bars encodes magnitude with length.
- Color Scales encodes the position of a value in a range.
- Icon Sets divides values into threshold bands.
Choose the boundaries deliberately. A built-in icon preset may use relative or percentage thresholds. For a business target, explicit numeric thresholds such as 0.8 and 1 are clearer than assuming that the green icon of a preset always means 100% of target.
Create a High-Revenue Highlight
For the Performance example, highlight the accounts with more than $120,000 revenue:
Select the Revenue cells and choose Highlight Cells Rules → Greater Than….
Confirm Applies To.
Enter
120000as the rule value. The numeric threshold has no currency symbol: the cells already contain numeric amounts and have a currency display format.Choose the green format.
Select Apply Rule.
The green highlights now identify Cedar Partners and Northstar Labs. Changing the revenue of an account below the threshold removes its matching conditional highlight, and its base formatting remains.
Important
Strict Comparison. Values equal to 120000 do not match a strict greater-than condition.
Preview a Rule Before Applying
The New Formatting Rule dialog keeps Rule Type and Applies To above its collapsible settings. Rule Criteria, Appearance and Thresholds show the controls that apply to the chosen rule. Opening one section closes the previous section while the dialog header, preview and actions stay in place.

The Live Preview renders representative data bars, color scales or icons using the draft settings; value and expression formats preview their text appearance. The samples help compare colors and thresholds before Apply Rule writes the rule. Cancel discards the draft. Preview samples do not replace testing actual boundary values in the target range.
Manage Overlapping Rules
Choose Conditional Formatting → Manage Rules… to review the rules and their target ranges:

- Scope. Use the scope selector to inspect the selection or the worksheet.
- Applies To. Check Applies To before editing a rule.
- Edit and delete. The edit and delete actions target a particular rule.
- Priority. The up and down actions change the priority.
- Stop If True. Where available, Stop If True prevents lower-priority rules from contributing when that rule matches.
The manager shares the fixed dialog heading and footer. Its rule list scrolls while the scope selector and New Rule… / Close actions remain available. Each row supplies a format sample, so the manager does not need a separate preview panel. Commands update the worksheet rules; Close finishes the review.
Overlapping rules can supply different aspects of the appearance. In the example, Revenue can have a data bar and a green highlight together. If the result is unexpected, inspect the rule order and scope before changing the direct fill of the cell. Clearing a conditional rule and clearing the content of a cell are different operations.
Define the Same Rules in Code
The following code adds a data bar to the existing Performance sheet. Select the owning worksheet before you use these workbook-level rule methods. editor is the Spreadsheet of the browser editor:
const sheet = editor.workbook.sheets.get('Performance');
editor.ui.selectSheet(sheet);
editor.workbook.addConditionalRule({
type: 'dataBar', ranges: ['B4:B9'],
color: '#638ec6', gradient: false
});
The code works as follows:
Workbook.sheetsandSheetCollection.getfind the worksheetPerformanceby its case-insensitive name.getthrows when the sheet is absent.editor.ui.selectSheetselects the worksheet, because the rule methods of the workbook work on the active sheet.Workbook.addConditionalRuleadds a rule of the typedataBartoB4:B9, with the bar color#638ec6and no gradient, and returns the stable ID of the rule.
listConditionalRules(range) returns detached rule definitions. Use updateConditionalRule and deleteConditionalRule with the stable ID of a rule to maintain it. Consult ConditionalRule for the payload of each kind: data bars, color scales, icons, expression rules and value rules have different fields.
Reuse Formatting With Named Styles and Themes
listNamedStyles() enumerates the workbook styles. createCellStyle, updateCellStyle and applyCellStyle provide reusable base formatting. Updating a shared named style affects its users, so choose meaningful names and review the affected cells.
Workbook theme colors, set with Workbook.setTheme, coordinate cells, charts and supported document formatting. Changing a workbook theme is separate from switching the light or dark interface of the application, which Appearance and Localization describes.
Table styles remain attached to their tables. A conditional rule supplies its calculated appearance on top of the applicable base formatting.
Which Formatting Mechanism to Use
| Mechanism | What it does |
|---|---|
| Named cell style | Supplies reusable base formatting |
| Table style | Formats an operational table |
| Conditional formatting | Calculates an effective appearance from a rule |
Choose the mechanism that matches the requirement rather than replacing a dynamic rule with manual colors. A shared named style is useful for a report-wide heading change. It does not replace a rule that must react when an amount crosses a threshold.
Review and Test Rules
- Review rules as a whole. Keep the target range, thresholds, priority and expected result together when you review rules.
- Test the boundaries. Test exact boundary values as well as typical values, and test blanks, errors and overlapping rules.
- Check the output. Review the exported PDF as well as the grid.
- XLSX. XLSX carries supported native conditional definitions. Specialized imported rules may require preservation rather than editing.
Formula Rules and Pattern Fills
Excel expression rules use the shared calculation engine and retain rule priority and Stop If True. Within a conditional expression, relative named formulas are resolved from the current cell; ordinary API-defined names retain their fixed-reference behavior. Conditional formatting takes precedence over direct and table formatting.
Rule formatting accepts text and fill colors, font family and point size, emphasis, border edges, numeric format codes and fillPattern. A solid conditional fill replaces a lower-priority hatch. The cell's stored content and base formatting stay unchanged. Canvas and PDF use the same resolved styles.
Choose Custom Format in the rule's Appearance section to edit Pattern Style and Pattern Color. Leave Use Fill Color off to draw the pattern over the cell's existing background, or enable it to supply a background as well. None explicitly removes the matching cell's pattern when selected. The live preview and rule-manager samples show the pattern; the cell's base formatting stays unchanged.
For example, the following expression rule marks positive amounts with a diagonal hatch:
editor.workbook.addConditionalRule({
type: 'expression',
ranges: ['B4:B9'],
formula: '=B4>0',
formatting: { fillPattern: { type: 'lightUp', color: '#735773' } }
});
Next Steps
- Format Cells Dialog: set the base formatting of a selection, section by section.
- Tables: format an operational table with a table style.
- Formatting and Number Display: format ranges in code and choose number formats.
- XLSX Compatibility: validate how a workbook with rules survives the exchange as XLSX.