diff --git a/src/ods.rs b/src/ods.rs index 9b0247da..6f503307 100644 --- a/src/ods.rs +++ b/src/ods.rs @@ -663,6 +663,7 @@ where RS: Read + Seek, { let mut is_string = false; + let mut is_error = false; let mut is_value_set = false; let mut val = Data::Empty; let mut formula = String::new(); @@ -691,15 +692,18 @@ where is_value_set = true; } "office:value-type" if !is_value_set => is_string = value == "string", + "calcext:value-type" => is_error = value == "error", "table:formula" => { formula = decode_attr(value)?; } _ => (), } } - if !is_value_set && is_string { + if (!is_value_set && is_string) || (is_error && matches!(&val, Data::String(s) if s.is_empty())) + { // If the value type is string and the office:string-value attribute - // is not present, the element content defines the value. + // is not present, the element content defines the value. LibreOffice + // also stores error text in the content with an empty string-value. let mut s = String::new(); let mut first_paragraph = true; loop { diff --git a/tests/cached_error_text.ods b/tests/cached_error_text.ods new file mode 100644 index 00000000..5881ba2e Binary files /dev/null and b/tests/cached_error_text.ods differ diff --git a/tests/test.rs b/tests/test.rs index e222e039..b5bf08b7 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -260,6 +260,23 @@ fn ods_covered() { ); } +#[test] +fn ods_cached_error_text() { + let mut excel: Ods<_> = wb("cached_error_text.ods"); + let range = excel.worksheet_range("Sheet1").unwrap(); + range_eq!( + range, + [ + [String("#DIV/0!".to_string())], + [String("#DIV/0!".to_string())], + [String("".to_string())], + [String("cached".to_string())], + ] + ); + let formulas = excel.worksheet_formula("Sheet1").unwrap(); + range_eq!(formulas, [["of:=1/0"]; 4]); +} + #[test] fn special_cells() { let mut excel: Ods<_> = wb("special_cells.ods");