Skip to content

Don't panic on quoted text around a number placeholder - #376

Merged
MathNya merged 1 commit into
MathNya:masterfrom
keithadler:fix-quoted-number-format
Oct 1, 2026
Merged

MathNya merged 1 commit into
MathNya:masterfrom
keithadler:fix-quoted-number-format

Conversation

@keithadler

Copy link
Copy Markdown
Contributor

Problem

Cell::formatted_value() panics on any numeric cell whose number format starts and ends with a quote but has a placeholder in between, such as "Qty "0" pcs" or "Total: "#,##0.00" EUR":

thread 'main' panicked at src/helper/number_format.rs:130:67:
called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }

to_formatted_string treats every format that starts and ends with " as a quoted number and calls format.trim_matches('"').parse::<f64>().unwrap(). For these formats the trimmed text is Qty "0" pcs, which is not a number. (Formats that are only quoted text, like " Excellent" in Apache POI's ConditionalFormattingSamples.xlsx, are already handled by literal_only_section on master; they panicked in 3.1.0.)

Change

Take that branch only when the quoted text really parses as a number. Everything else falls through to the number formatter, which already renders these the way Excel does: Qty 5 pcs, Total: 1,234.50 EUR.

Tests

test_to_formatted_string_quoted_text_around_a_placeholder in helper/number_format.rs; it panics without the change. cargo +nightly fmt --all --check, cargo clippy -- -D warnings and cargo test pass.

Found by differential testing with xlsx-lean and Apache POI's test files.

🤖 Generated with Claude Code

https://claude.ai/code/session_019hXzkiuCwk5QQRsyU9wT9h

`to_formatted_string` treated any section that starts and ends with a
quote as a quoted number and called `parse::<f64>().unwrap()` on it.
Formats such as `"Qty "0" pcs"` or `"Total: "#,##0.00" EUR"` start and
end with a quote but are text around a placeholder, so
`Cell::formatted_value()` panicked with `ParseFloatError` on any cell
that used one.

Take that branch only when the quoted text really is a number, and let
everything else go through the number formatter, which already renders
these as Excel does ("Qty 5 pcs", "Total: 1,234.50 EUR").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019hXzkiuCwk5QQRsyU9wT9h
@MathNya

MathNya commented Oct 1, 2026

Copy link
Copy Markdown
Owner

@keithadler
Thank you for the PR.
Since there were no issues, I’ll go ahead and merge it.

@MathNya
MathNya merged commit c9aafe7 into MathNya:master Oct 1, 2026
5 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.

3 participants