From d75b6b73b43804de83a5baa3ac9030fff00707fd Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Sat, 10 Oct 2026 00:56:12 -0500 Subject: [PATCH] Criteria: text patterns don't match blank cells COUNTIF(range,"*") counted empty cells and COUNTIF(range,"<>*") skipped them. Excel matches text patterns against text only: an empty string is text, a blank cell is not. --- crates/functions/src/criteria.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/functions/src/criteria.rs b/crates/functions/src/criteria.rs index 49d84a3..20410c8 100644 --- a/crates/functions/src/criteria.rs +++ b/crates/functions/src/criteria.rs @@ -127,9 +127,9 @@ impl Criterion { }, Operand::Text(pat) => match self.op { Op::Eq | Op::Ne => { + // Blank cells hold no text: `"*"` skips them and `"<>*"` counts them. let cell_text = match &v { Value::Text(t) => Some(t.to_string()), - Value::Empty => Some(String::new()), _ => None, }; let m = cell_text.is_some_and(|t| wildcard_match(pat, &t)); @@ -298,6 +298,13 @@ mod tests { assert!(lookup_equal(&Value::Number(0.3), &Value::Number(0.1 + 0.2), false)); assert!(m("<>a*", Value::from("bcd"))); assert!(m(">1/1/2020", Value::Number(44000.0))); + // Text patterns never match blank cells, but an empty string is text. + assert!(!m("*", Value::Empty)); + assert!(m("*", Value::from(""))); + assert!(m("<>*", Value::Empty)); + assert!(!m("<>*", Value::from(""))); + assert!(!m("?*", Value::Empty)); + assert!(m("<>a*", Value::Empty)); } #[test]