theorchard / openpyxl

Other
58 stars 21 forks source link

Openpyxl fails to read excel with filters #55

Closed aersam closed 5 months ago

aersam commented 5 months ago

Hi guys

I use openpyxl to read Tables in Excel files, and actually I do not care about table filters at all. However, I sometimes get exceptions from filter stuff, such as this:

    101         attrib[tag] = obj
--> 103 return cls(**attrib)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-a0a4f445-0d4d-47e1-ab0b-c56498e3da4e/lib/python3.10/site-packages/openpyxl/worksheet/filters.py:184, in CustomFilter.__init__(self, operator, val)
    183 self.operator = operator
--> 184 self.val = val
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-a0a4f445-0d4d-47e1-ab0b-c56498e3da4e/lib/python3.10/site-packages/openpyxl/worksheet/filters.py:165, in CustomFilterValueDescriptor.__set__(self, instance, value)
    164 if not m:
--> 165     raise ValueError("Value must be either numerical or a string containing a wildcard")
    166 if "*" in value:
ValueError: Value must be either numerical or a string containing a wildcard

The above exception was the direct cause of the following exception:
ValueError                                Traceback (most recent call last)

It would be really nice to have a mode to just ignores such errors or even better just skip skip parsing anything other than actual data.

Btw, the error in this particular case is because of an empty string:

image

and this is the value of "instance": image

Which I think is because of a filter like this in excel:

image