Open xxggabriel opened 4 weeks ago
Although the Excel GUI shows a Contains option, it appears to be translated internally to a custom filter using equals (for contains) or not equals (for doesn't contain). So, to check for c
in your example:
$columnFilter
->setFilterType(
Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER
);
$columnFilter->createRule()
->setRule(
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'*c*'
)
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
This isn't really any more complicated than your proposed code, except for the addition of the asterisks at the beginning and end of the string. So I don't think any new code is required for PhpSpreadsheet. It might be worthwhile to add this to the formal documentation. I will think about that.
This is:
What is the expected behavior?
The expected behavior is to have additional flexibility in the AutoFilter functionality by introducing two new filter rules: CONTAINS and DOESNTCONTAIN. These rules should allow users to filter rows based on whether a cell value contains or does not contain a specified substring. This feature will help users perform more refined data analysis directly within PhpSpreadsheet.
What is the current behavior?
Currently, the AutoFilter feature in PhpSpreadsheet does not support direct filtering based on substring matches. Users who need to filter rows that contain or do not contain a particular string have to implement workarounds or use more basic comparison rules.
What are the steps to reproduce?
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
The feature request is related to the AutoFilter functionality and is not specific to any particular file format.
Which versions of PhpSpreadsheet and PHP are affected?
The current feature request is applicable for all versions of PhpSpreadsheet and PHP where AutoFilter functionality is available.