Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/ods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
Binary file added tests/cached_error_text.ods
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading