Skip to content

Show spreadsheet numbers as the sheet states them — a percent cell reads 0.153 where Excel says 15.3%, for reader and assistant alike #161

Closed

Description

@bencode

Problem

A cell Excel shows as 15.3% Gamma Reader shows as 0.153; ¥12,345.60 shows as 12345.6; a value rounded by its format to 2.35 shows its floating-point noise. The number format that states what a number means is dropped on the way in:

  • read-excel-file (9.3.10) consults cell styles only to decide date-vs-number (modules/xlsx/parseCell.js:236–249); every other format — percent, currency, fixed decimals — is discarded and the raw serial value returned.
  • readSpreadsheet carries no formats out (ui-packages/web/src/formats/xlsx.ts:127, Worksheet = { name, rows }), and cellText has no formatting knowledge (xlsx.ts:74–79), so both the grid (sheet-grid.tsx:89) and the agent's sheet_read/sheetText (features/assistant/xlsx/tools.ts) render the raw number.
  • The loss is not cosmetic: a percent column read as 0.053 is ambiguous — the reader cannot tell 5.3% from 0.053%, and neither can the assistant, because the format that disambiguated it is gone before either sees it. Dates, notably, do get faithful treatment (xlsx.ts:67–70) — the product already cares about format fidelity where the parser helps.

Proposal

  • Read the workbook's xl/styles.xml + numFmts alongside the cells — the same pre-read-the-zip precedent docx-unconverted.ts set for Word — and map each cell to its format code.
  • Apply a minimal formatter for the common classes the way the sheet states them: percent (15.3%, value × 100 with the format's decimals), currency and thousands-grouped fixed decimals, plain raw number otherwise.
  • Route the formatted text through cellText so the grid, sheetText (read/search) and sheet_read all state the same value the reader would see in Excel.

Goal

After this, a percent-formatted cell renders 15.3% and a currency cell ¥12,345.60 in the preview, and sheet_read returns the same text — no cell whose format states a scale or precision reads as a different-looking raw number.

Verification

# the format knowledge must exist in the deliverable before the tests can see it;
# fails today (cellText emits 0.153 via String(value)), passes once numFmt mapping lands
grep -rqiE 'numFmt|formatCode|percent|currency|Intl\.NumberFormat' ui-packages/web/src/formats/xlsx.ts
# fixture workbook with percent- and currency-formatted cells;
# grid text and sheetText state "15.3%" / "12,345.60" instead of 0.153 / 12345.6
cd ui-packages/web && pnpm vitest run --project unit src/formats/xlsx.test.ts

Refs

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 21, 2026
  2. bencode commented on Oct 21, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session.

    Evidence audit (main @ ebb0ee0): all citations hold.

    • cellText has no formatting knowledge — String(value) for numbers (formats/xlsx.ts:74–79); dates are the existing fidelity precedent (xlsx.ts:66–70).
    • readSpreadsheet drops formats at the boundary — returns { name, rows } only (xlsx.ts:127–131).
    • read-excel-file@9.3.10 consults styles solely for date-vs-number; every other format discards to the raw serial (modules/xlsx/parseCell.js:236–249).
    • Grid renders through cellText (sheet-grid.tsx:89).
    • One anchor precision: sheetText/workbookText live in formats/xlsx.ts (workbookText feeds the generic read/search tools); sheet_read reaches cellText via selectCells (xlsx.ts:115–122) imported by features/assistant/xlsx/tools.ts. All paths do meet at cellText, so the seam is right — the ref just shouldn't imply sheetText lives in tools.ts.

    Sensor: lint passed. verify "passed" is a false positive — the cited xlsx.test.ts passes on main only because it contains no percent/currency assertions yet; cellText today emits 0.153.

    Sharpening suggestions:

    1. Name the new fixture + test titles in the Verification block (e.g. "a percent-formatted cell renders 15.3% in grid text and sheetText"), so the verify gate distinguishes implemented from vacuous pass.
    2. Format mapping needs xl/styles.xml numFmts and cellXfs/@numFmtId — builtin ids (0x08 currency, 0x09/0x0A percent) don't appear in numFmts, only custom ones do.
    3. Routing through cellText covers grid, sheetText and selectCells (sheet_read) at one seam — confirmed the right choice.

    Duplicates: none in open+closed titles — #157 is the hidden-cell sibling, distinct failure mode.

    Verdict: valid — stays open.

  3. bencode commented on Oct 25, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Audited against main@90b046f.

    Evidence audit: anchors hold. No commit since the first review (ebb0ee0 → 90b046f) touches formats/xlsx.ts; cellText (:74-79) still does String(value), readSpreadsheet (:127-131) still drops formats, and the grid still renders through cellText (sheet-grid.tsx:89, loop variable renamed i → item.index — cosmetic). Code confirms not implemented: no numFmt/percent/currency/Intl.NumberFormat anywhere in formats/xlsx.ts.

    Duplicate check: still none — #157 (hidden cells) is the sibling, distinct failure mode; no other percent/format issue in open+closed.

    Verification block repaired (logged here per policy): verify was passing vacuously — xlsx.test.ts runs 14 tests that pass on unmodified main, so the gate reported nothing implemented as implemented (same disease the #157 repair fixed). Prepended a discriminating grep over the deliverable surface:

    grep -rqiE 'numFmt|formatCode|percent|currency|Intl\.NumberFormat' ui-packages/web/src/formats/xlsx.ts

    It fails today ✓, re-linted ✓, verify now fails today ✓ (was falsely passing). Any implementation must touch number-format knowledge in formats/xlsx.ts, whichever spelling it chooses.

    Verdict: valid, stays open. The first review's sharpenings stand: name the fixture/test titles, and remember builtin numFmt ids (0x08/0x09/0x0A) live only in cellXfs/@numFmtId, not in numFmts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions