Skip to content

Add numberFormat support to formatCells tool#82

Merged
a-bonus merged 1 commit intoa-bonus:mainfrom
heyrocker:feat/number-format
Mar 14, 2026
Merged

Add numberFormat support to formatCells tool#82
a-bonus merged 1 commit intoa-bonus:mainfrom
heyrocker:feat/number-format

Conversation

@heyrocker
Copy link
Copy Markdown
Contributor

Summary

Adds an optional numberFormat parameter to the existing formatCells tool, allowing callers to control how cell values are displayed and — importantly — to clear persistent number formats that survive a standard formatting reset.

Motivation

Google Sheets auto-parses strings like "3/9" as dates when written with USER_ENTERED value input. This applies a date number format to the cell. Subsequent formatCells calls that reset bold, fontSize, and backgroundColor do not clear the number format, because numberFormat wasn't included in the fields mask. As a result, integer values written to those cells in later runs would display as 1900-era dates (e.g. 9"1/9" because January 9, 1900 is serial number 9).

Setting numberFormat: { type: "TEXT" } explicitly resets the cell to plain text, clearing the lingering date format.

Changes

  • formatCells.ts: Adds numberFormat as an optional Zod object parameter with type (enum) and optional pattern (string). Updated description. Added to the "at least one option" refine check.
  • googleSheetsApiHelpers.ts: Added numberFormat to the format type. When present, sets userEnteredFormat.numberFormat and dynamically includes numberFormat in the fields mask so it's actually written (not just skipped).

API

numberFormat?: {
  type: 'TEXT' | 'NUMBER' | 'PERCENT' | 'CURRENCY' | 'DATE' | 'TIME' | 'DATE_TIME' | 'SCIENTIFIC';
  pattern?: string; // e.g. "0.00", "#,##0", "yyyy-MM-dd"
}
  • type: "TEXT" — treats cell as plain text; clears any existing date/number format
  • type: "NUMBER" — general numeric display
  • pattern — optional custom format code; if omitted, the type's default display is used

Test plan

  • Write "3/9" with USER_ENTERED, confirm it becomes date-formatted. Then call formatCells with numberFormat: { type: "TEXT" } and verify integer values in those cells display as plain numbers.
  • Apply numberFormat: { type: "NUMBER", pattern: "0.0" } — verify one decimal place display
  • Apply numberFormat: { type: "DATE", pattern: "yyyy-MM-dd" } — verify date display
  • Confirm existing bold/fontSize/backgroundColor resets still work when numberFormat is not passed (fields mask is unchanged for those calls)
  • Confirm Zod accepts numberFormat alone as a valid "at least one option" case

🤖 Generated with Claude Code

Adds an optional `numberFormat` parameter to `formatCells`, allowing
callers to control how cell values are displayed and to clear persistent
number formats (such as date formats applied when Google Sheets parses
a string like "3/9" as a date).

Accepted types: TEXT, NUMBER, PERCENT, CURRENCY, DATE, TIME, DATE_TIME,
SCIENTIFIC. An optional `pattern` string supports custom format codes
(e.g. "0.00", "#,##0", "yyyy-MM-dd").

The most common use case is clearing date format persistence: when cells
previously had a date-format applied (by Sheets auto-parsing a string
as a date), a subsequent formatCells reset did not clear the number
format. Passing `numberFormat: { type: "TEXT" }` now explicitly resets
it to plain text, so integer values display correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@a-bonus a-bonus merged commit 4a83539 into a-bonus:main Mar 14, 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