From c370ff2a3825e56b50968f32e98946858f0700f8 Mon Sep 17 00:00:00 2001 From: Johann Tuffe Date: Tue, 19 Dec 2023 16:46:44 +0800 Subject: [PATCH 1/2] fix missing formula for xlsx --- Changelog.md | 4 ++++ src/xlsx/cells_reader.rs | 2 +- tests/test.rs | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8566b796..13765ffa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/xlsx/cells_reader.rs b/src/xlsx/cells_reader.rs index 1a768225..16a32a23 100644 --- a/src/xlsx/cells_reader.rs +++ b/src/xlsx/cells_reader.rs @@ -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); diff --git a/tests/test.rs b/tests/test.rs index b1803a9d..5f317f23 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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::>(); + assert_eq!(range.used_cells().collect::>(), 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::>(); + 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) +} From ae56b064257a0b7fdf82d0176ddc9e4afa4f3d85 Mon Sep 17 00:00:00 2001 From: Johann Tuffe Date: Tue, 19 Dec 2023 16:48:20 +0800 Subject: [PATCH 2/2] bump v0.23.1 --- Cargo.toml | 2 +- tests/formula.issue.xlsx | Bin 0 -> 8626 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 tests/formula.issue.xlsx diff --git a/Cargo.toml b/Cargo.toml index 4b23acc3..c12e06a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calamine" -version = "0.23.0" +version = "0.23.1" authors = ["Johann Tuffe "] repository = "https://github.com/tafia/calamine" documentation = "https://docs.rs/calamine" diff --git a/tests/formula.issue.xlsx b/tests/formula.issue.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..65fa1d603c83020dda40063e2c32727d0dd8b776 GIT binary patch literal 8626 zcmeHsgG>k zzrDBn{QiP-)?D+hiFH5MTI;><_kPy%fE7_ti2&#TOaK5t1Hj!`{h^Np07Rn#0E7Tc zWPM2|M|Vp{cVi77XG=FjR&NJ;>U>mWhFkzL;`sk<|HXHpJbBm=nFiQ%pnQFgyz)!v z`3N_(32Hr;mR1rg_w#9Dp<6sZ&i~bV!R@imn$kkKtVR{AOlA z3ibggURq=j>`j529e&IjqG-9zJ>z|fU2ia}(c-XqG9-^0SN?h*Sx~Fn0&|KXy{|+^ z@HR?)A1jN~4VRaG8D-WaKW$|1JO0c@fVxfoD0t99=}`@c+|0Z?J|5qIZA>a>|{{iX1@IbEAXC7;@huKsQU)2!^)qo$qDGwvM7vj}6p4xZpAVC8eRhO#!}(xGyYJ>!*KdMt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