Skip to content

Commit

Permalink
Merge pull request #388 from tafia/fix384
Browse files Browse the repository at this point in the history
Fix384
  • Loading branch information
tafia authored Dec 19, 2023
2 parents a58e8a5 + ae56b06 commit ad57593
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calamine"
version = "0.23.0"
version = "0.23.1"
authors = ["Johann Tuffe <[email protected]>"]
repository = "https://github.com/tafia/calamine"
documentation = "https://docs.rs/calamine"
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

## Unreleased

## 0.23.1

- fix: `worksheet_formula` not returning all formula

## 0.23.0

- feat: add new `DataTypeRef` available from `worksheet_range_ref` to reduce memory usage
Expand Down
2 changes: 1 addition & 1 deletion src/xlsx/cells_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'a> XlsxCellReader<'a> {
}
}
self.col_index += 1;
return Ok(value.map(|value| Cell::new(pos, value)));
return Ok(Some(Cell::new(pos, value.unwrap_or_default())));
}
Ok(Event::End(ref e)) if e.local_name().as_ref() == b"sheetData" => {
return Ok(None);
Expand Down
Binary file added tests/formula.issue.xlsx
Binary file not shown.
38 changes: 38 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,3 +1527,41 @@ fn issue_385() {
"Is expeced to return XlsError::Password error"
);
}

#[test]
fn issue_384_multiple_formula() {
let path = format!("{}/tests/formula.issue.xlsx", env!("CARGO_MANIFEST_DIR"));
let mut workbook: Xlsx<_> = open_workbook(path).unwrap();

// first check values
let range = workbook.worksheet_range("Sheet1").unwrap();
let expected = [
(0, 0, DataType::Float(23.)),
(0, 2, DataType::Float(23.)),
(12, 6, DataType::Float(2.)),
(13, 9, DataType::String("US".into())),
];
let expected = expected
.iter()
.map(|(r, c, v)| (*r, *c, v))
.collect::<Vec<_>>();
assert_eq!(range.used_cells().collect::<Vec<_>>(), expected);

// check formula
let formula = workbook.worksheet_formula("Sheet1").unwrap();
let formula = formula
.used_cells()
.map(|(r, c, v)| (r, c, v.as_str()))
.collect::<Vec<_>>();
let expected = [
(0, 0, "C1+E5"),
// (0, 2, DataType::Float(23.)),
(12, 6, "SUM(1+1)"),
(
13,
9,
"IF(OR(Q22=\"\",Q22=\"United States\"),\"US\",\"Foreign\")",
),
];
assert_eq!(formula, expected)
}

0 comments on commit ad57593

Please sign in to comment.