Skip to content

Add addConditionalFormatting tool (BooleanRule)#81

Merged
a-bonus merged 1 commit intoa-bonus:mainfrom
heyrocker:feat/conditional-formatting
Mar 15, 2026
Merged

Add addConditionalFormatting tool (BooleanRule)#81
a-bonus merged 1 commit intoa-bonus:mainfrom
heyrocker:feat/conditional-formatting

Conversation

@heyrocker
Copy link
Copy Markdown
Contributor

Summary

Adds a new addConditionalFormatting tool that appends a BooleanRule conditional format rule to one or more ranges in a spreadsheet via batchUpdate.

What's supported

Condition types:

  • NUMBER_GREATER, NUMBER_GREATER_THAN_EQ, NUMBER_LESS, NUMBER_LESS_THAN_EQ — single value comparisons (e.g. conditionValues: ["40"])
  • NUMBER_EQ, NUMBER_NOT_EQ — equality comparisons
  • NUMBER_BETWEEN, NUMBER_NOT_BETWEEN — requires exactly two values (lower bound first)
  • BLANK, NOT_BLANK — no condition values
  • CUSTOM_FORMULA — arbitrary formula string (e.g. "=$A1>$B1")

Format options: backgroundColor (hex), bold, italic, strikethrough, underline, foregroundColor (hex), fontSize

Other: sheetName (optional, defaults to first sheet), ranges (array of A1 notation strings, min 1)

What's not supported

  • GradientRule — the Sheets API has a separate GradientRule type for continuous color scales (min/mid/max). This tool only implements BooleanRule. GradientRule would be a separate tool.
  • Updating existing rules — each call appends a new rule. Use deleteConditionalFormatting (not yet implemented) to remove rules before re-adding.
  • Text-based conditionsTEXT_CONTAINS, TEXT_NOT_CONTAINS, TEXT_STARTS_WITH, TEXT_ENDS_WITH, TEXT_EQ are valid Sheets API condition types but not exposed here. Can be added if needed.
  • Date conditionsDATE_EQ, DATE_BEFORE, DATE_AFTER, etc. — not currently exposed.

Validation

Zod .refine() validates that the correct number of conditionValues is provided per condition type:

  • 0 values for BLANK / NOT_BLANK
  • 2 values for NUMBER_BETWEEN / NUMBER_NOT_BETWEEN
  • 1 value for all other types
  • At least one format option must be specified

Implementation notes

  • Logic delegated to a new addConditionalFormatRule helper in googleSheetsApiHelpers.ts
  • Follows the same pattern as formatCells and other formatting tools
  • Uses parseA1ToGridRange to convert A1 notation to Schema$GridRange objects

Test plan

  • Apply a NUMBER_GREATER rule with backgroundColor — verify cells exceeding threshold turn the expected color
  • Apply a CUSTOM_FORMULA rule — verify formula-based highlighting works
  • Apply a BLANK rule (no conditionValues) — verify it doesn't reject the call
  • Apply a NUMBER_BETWEEN rule with two values — verify range highlighting works
  • Confirm Zod validation rejects mismatched conditionValues counts
  • Confirm at least one format option is required (Zod refine)

🤖 Generated with Claude Code

Adds a new `addConditionalFormatting` tool that appends a BooleanRule
conditional format rule to one or more ranges in a spreadsheet. Applies
a format (background color, bold, text color, etc.) when cells meet a
specified condition.

Supported condition types:
- NUMBER_GREATER, NUMBER_GREATER_THAN_EQ, NUMBER_LESS, NUMBER_LESS_THAN_EQ
- NUMBER_EQ, NUMBER_NOT_EQ
- NUMBER_BETWEEN, NUMBER_NOT_BETWEEN (requires two condition values)
- BLANK, NOT_BLANK (no condition values)
- CUSTOM_FORMULA (e.g. "=$A1>$B1")

Supported format options: backgroundColor, bold, italic, strikethrough,
underline, foregroundColor, fontSize.

Not supported: GradientRule (continuous color scale) — this is a separate
rule type in the Sheets API and would be a separate tool.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@a-bonus a-bonus merged commit 2b0786a into a-bonus:main Mar 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants