From 28cb51554a90f99bc62d72f7b6404c98a4ece91e Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:23:34 +0100 Subject: [PATCH] textimport: show XLSX number cells that aren't numbers as written (#2734) --- crates/textimport/src/xlsx.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/textimport/src/xlsx.rs b/crates/textimport/src/xlsx.rs index f27c305f0..f49bdd220 100644 --- a/crates/textimport/src/xlsx.rs +++ b/crates/textimport/src/xlsx.rs @@ -39,8 +39,9 @@ fn sheet_cells( let result = package.sheet(entry, |row| { for cell in row.cells { let value = match cell.value { - // Retain legacy display of non-finite spellings such as `inf`. - craft_xlsx::CellValue::Invalid(raw) => raw.parse::().map(general).unwrap_or_default(), + // A value that doesn't read as its type says (`inf`, `n/a` in a number cell) is + // shown as written, as the importer did before the shared reader. + craft_xlsx::CellValue::Invalid(raw) => raw, value => display(value.resolve(&strings, date_1904)), }; text_bytes = text_bytes.saturating_add(value.len()); @@ -419,6 +420,15 @@ mod tests { } } + #[test] + fn number_cells_that_are_not_numbers_show_as_written() { + for text in ["inf", "Infinity", "NaN", "n/a", "12 apples"] { + let book = one_value(&format!(r#"{text}"#)); + let rows = crate::xlsx_records(&book, None).unwrap(); + assert_eq!(rows[1][0], text, "cell {text}"); + } + } + #[test] fn cached_string_values_are_not_reformatted_as_numbers() { for text in ["00123", "1e3", "12.0", " 42 "] {