mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-23 19:04:06 +01:00
textimport: show XLSX number cells that aren't numbers as written (#2734)
This commit is contained in:
1 parent
e43c78b4d4
commit
28cb51554a
1 file changed
+12
-2
@@ -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::<f64>().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#"<c r="A2"><v>{text}</v></c>"#));
|
||||
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 "] {
|
||||
|
||||
Reference in new issue
Block a user