CustomFilterValueDescriptor: Don't raise in case values only contain spaces
Encountered this value error this when trying to read a (maybe somewhat invalid?) file. This patch helped me getting around this. I really can't give you the file and I also still don't have any idea where exactly this bad value appears.
As I can neither fork or push to this repo, here is the patch:
$ hg tip -p
changeset: 9502:619eda28646e
tag: tip
topic: CustomFilterValueDescriptor-non-empty-values
parent: 9447:b1807ec23379
user: Sebastian Wagner
date: Thu Feb 22 15:20:01 2024 +0100
summary: CustomFilterValueDescriptor: Don't raise in case values contain spaces
diff -r b1807ec23379 -r 619eda28646e openpyxl/worksheet/filters.py
--- a/openpyxl/worksheet/filters.py Sat Mar 11 18:01:30 2023 +0100
+++ b/openpyxl/worksheet/filters.py Thu Feb 22 15:20:01 2024 +0100
@@ -160,9 +160,12 @@
def __set__(self, instance, value):
if isinstance(value, str):
- m = self.pattern.match(value)
- if not m:
- raise ValueError("Value must be either numerical or a string containing a wildcard")
+ if not value.strip():
+ self.expected_type = str
+ else:
+ m = self.pattern.match(value)
+ if not m:
+ raise ValueError(f"Value must be either numerical or a string containing a wildcard.")
if "*" in value:
self.expected_type = str
super().__set__(instance, value)