Overview
AutoFilters allow users to filter data in Excel worksheets. PhpSpreadsheet can create autofilters and even pre-configure filter rules that Excel will apply when the file is opened.Basic AutoFilter
The simplest way to add an autofilter is to enable it for your data range:Always include the complete filter range including headers. While Excel supports setting only the caption row, it’s best practice to include all data rows.
Custom Filter Rules
You can pre-configure filter rules that Excel will apply automatically:When using wildcards in filters, you must set the filter type to
AUTOFILTER_FILTERTYPE_CUSTOMFILTER.Filtering by Value List
Filter to show only specific values:Date Group Filters
Filter dates by day, month, or year:Filtering Blank Values
Filter to show only blank cells:Numeric Filters
Apply filters based on numeric comparisons:Available Comparison Operators
AUTOFILTER_COLUMN_RULE_EQUAL- EqualsAUTOFILTER_COLUMN_RULE_NOTEQUAL- Not equalAUTOFILTER_COLUMN_RULE_GREATERTHAN- Greater thanAUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL- Greater than or equalAUTOFILTER_COLUMN_RULE_LESSTHAN- Less thanAUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL- Less than or equal
Combined Filters (AND/OR)
Combine multiple filter conditions:Dynamic Filters
Use dynamic date filters:Available Dynamic Filters
AUTOFILTER_RULETYPE_DYNAMIC_TODAYAUTOFILTER_RULETYPE_DYNAMIC_YESTERDAYAUTOFILTER_RULETYPE_DYNAMIC_TOMORROWAUTOFILTER_RULETYPE_DYNAMIC_THISWEEKAUTOFILTER_RULETYPE_DYNAMIC_LASTWEEKAUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEKAUTOFILTER_RULETYPE_DYNAMIC_THISMONTHAUTOFILTER_RULETYPE_DYNAMIC_LASTMONTHAUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTHAUTOFILTER_RULETYPE_DYNAMIC_THISQUARTERAUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTERAUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTERAUTOFILTER_RULETYPE_DYNAMIC_THISYEARAUTOFILTER_RULETYPE_DYNAMIC_LASTYEARAUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR
Applying Filters in PhpSpreadsheet
By default, filter rules are defined but not executed. Excel will apply them when opening the file. To apply filters in PhpSpreadsheet:Complete Example
Here’s a complete example with multiple filters:Expected Result
When you open the Excel file:- Drop-down arrows appear in the header row
- Clicking them shows filter options
- Pre-configured filters are already applied
- Only rows matching all filter criteria are visible
- Filtered row numbers appear in blue in Excel

