Add numberFormat support to formatCells tool#82
Merged
a-bonus merged 1 commit intoa-bonus:mainfrom Mar 14, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
numberFormatparameter to the existingformatCellstool, 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 withUSER_ENTEREDvalue input. This applies a date number format to the cell. SubsequentformatCellscalls that resetbold,fontSize, andbackgroundColordo not clear the number format, becausenumberFormatwasn't included in thefieldsmask. 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: AddsnumberFormatas an optional Zod object parameter withtype(enum) and optionalpattern(string). Updated description. Added to the "at least one option" refine check.googleSheetsApiHelpers.ts: AddednumberFormatto the format type. When present, setsuserEnteredFormat.numberFormatand dynamically includesnumberFormatin thefieldsmask so it's actually written (not just skipped).API
type: "TEXT"— treats cell as plain text; clears any existing date/number formattype: "NUMBER"— general numeric displaypattern— optional custom format code; if omitted, the type's default display is usedTest plan
"3/9"withUSER_ENTERED, confirm it becomes date-formatted. Then callformatCellswithnumberFormat: { type: "TEXT" }and verify integer values in those cells display as plain numbers.numberFormat: { type: "NUMBER", pattern: "0.0" }— verify one decimal place displaynumberFormat: { type: "DATE", pattern: "yyyy-MM-dd" }— verify date displaybold/fontSize/backgroundColorresets still work whennumberFormatis not passed (fields mask is unchanged for those calls)numberFormatalone as a valid "at least one option" case🤖 Generated with Claude Code