Advanced AutoFilter execution
Use the lxHandleX worksheet APIs to inspect, preview or apply ordinary criteria and represented advanced filters without launching Excel
The execution path supports literal display-value selections, calendar date groups, Top/Bottom-n and percentage filters, relative calendar and average filters, effective fill/font colours and supported conditional icons
Entry points
Options := XLSDefaultAutoFilterExecutionOptions; Options.ReferenceDate := EncodeDate(2026, 10, 19); MatchingRows := Sheet.PreviewAutoFilterRows(nil, Options); Sheet.ApplyAutoFilter(True, Options);
TXLSXWorksheet.AutoFilterRowVisible(ARow, Options)evaluates one data rowTXLSXWorksheet.PreviewAutoFilterRows(Callback, Options)returns the matching data-row count and can optionally visit the matching rows; a nil callback performs a count-only previewTXLSXWorksheet.ApplyAutoFilter(AResetVisible, Options)prepares all row decisions before publishing visibility changes; True resets matching rows to visible, whilst False keeps matching rows that were already hidden
The existing overloads use the same default options returned by XLSDefaultAutoFilterExecutionOptions; initialise the whole TXLSXAutoFilterExecutionOptions record with this function before changing individual fields
Preview does not change row visibility; unsupported metadata, cancellation or a resource failure during preparation leaves the application's visibility unchanged
Values, dates and appearance
Selection-list entries are literal display tokens, including asterisks and question marks; ordinary custom text criteria keep their separate wildcard semantics
Selection tokens use the cell's base number format, including stored style overlays, even when conditional formatting changes its visible number format; colour and icon filters evaluate the supported effective conditional appearance
ReferenceDate freezes relative calendar and conditional date rules for an operation; zero takes the current date once at operation start, and numeric dates respect the workbook's date system
Formula cells need a loaded or calculated cache; filtering does not quietly recalculate the workbook
Resource limits
| Option | Default | Meaning |
|---|---|---|
| MaxXmlCharacters | 1048576 | Filter metadata text |
| MaxXmlNodes | 16384 | Parsed filter metadata nodes |
| MaxFilterItems | 4096 | Represented filter items |
| MaxExaminedCells | 4000000 | Cell reads during execution |
| MaxEffectiveFormatCells | 1000000 | Effective appearance evaluations |
| MaxPopulationValues | 1000000 | Collected ranking or average values |
| MaxContextBytes | 67108864 | Logical retained context and reserved temporary allocation envelopes |
| MaxConditionalSteps | 16000000 | Shared work across conditional evaluation, observed formatting, population sorting and selection-token comparison/insertion |
These are explicit positive bounds; MaxContextBytes measures logical ownership and reserved temporary envelopes rather than process RSS or cumulative allocator activity
OnWork is a TXLSXAutoFilterWorkEvent callback with the worksheet as Sender, examined cells as ACompleted and a mutable cancellation flag; ACompleted may stay unchanged whilst formatting or planning consumes work
The operation holds a workbook read lease whilst preparing decisions, so callbacks must not mutate that workbook; cancellation and callback exceptions propagate to the caller
Exceptions and current boundaries
EXLSXAutoFilterExecutionreports invalid execution stateEXLSXAutoFilterUnsupportedreports malformed or unsupported filter and appearance metadataEXLSXAutoFilterLimitreports an exceeded resource boundEXLSXAutoFilterCancelledreports work cancellation
Unsupported conditions fail explicitly rather than guessing a matching row set, taking in unknown filter extensions/calendars, unresolved differential styles or appearance colours, unsupported conditional metadata and external conditional compilation
Linear and path gradient fills do not match solid-colour or NoFill criteria, including their gradient-stop colours; an effective conditional solid-fill override still participates in matching; ordinary rich-text font colour filters match any nonempty run with a represented RGB, automatic or inherited base colour
Colour filters use direct cell styles and supported conditional overrides; visual fill and font colours supplied only by built-in or custom table styles do not participate, matching native Excel filtering; icon filters evaluate conditional icons directly
Unknown rich-text structure or colour metadata fails explicitly; known non-colour metadata such as font family, charset and scheme does not by itself prevent a colour-only match
Represented rich-text font colours also support conditional formatting, including rules that change only fill; explicit run colours remain effective, whilst runs without an explicit colour inherit the supported conditional or ordinary base font colour
Rich-text scanning reserves bounded scalar storage and reacquires the run count after its reservation work callback, then snapshots only colours and nonempty flags without copying text or font names; growth of the source beyond that reservation, spotted when reacquiring the runs, raises EXLSXAutoFilterLimit, whilst later callbacks traverse the owned snapshot
Conditional rich-text row decisions
Native colour filtering can reuse a result between equal-text rich and plain cells according to their base style and matching conditional rules, so the visible row set can depend on the order of those cells
HotXLS prepares the complete data range in ascending row order, even for AutoFilterRowVisible, so row inspection, preview and application use the same decisions
A matching conditional-rule path and the same represented base style allow reuse of the most recent result for the exact text; a different style or rule path computes a fresh result, and a row with no matching conditional rule always uses fresh ordinary matching
Conditional rules with identical resulting colours keep distinct rule identities, whilst equivalent stored base styles are compared by their represented content rather than their pool indexes
The preparation preserves case and every UTF-16 text unit, uses detached scalar decisions and stays bounded by the shared cell, formatting, work and context limits
Non-string values use fresh appearance matching; unknown rich-text colours, unresolved styles and unmodelled conditional metadata keep their explicit rejection behaviour
Guarded formatter and calculation consumers
TXLSFormater.CreateObserved(AWork, ABudget) preserves ordinary formatting behaviour whilst exposing work notifications and temporary byte reservations; TXLSFormater.ObservedPendingBytes is valid during the budget callback and resets afterwards, and either callback may stop formatting by raising
The observed formatter snapshots the locale fields its date mask needs ahead of later work callbacks, including owned era metadata where supported; ordinary construction keeps its existing behaviour
The formatter also reports the colour requested by the last formatted value: LastColor returns it in $00BBGGRR layout and HasLastColor stays False when the number format asked for no colour; both are valid immediately after GetDisplayValue or FormatDouble returns, and RememberColor maps a #RRGGBB literal, or one of the eight named bracket colours (red, green, blue, cyan, magenta, yellow, white, black), onto that layout
The formatter likewise reports the fill character left by the last formatted value: a *x repeat in the number format fills the rest of the cell width with x, HasFillCharacter stays False when the format has no fill or the value was formatted as HTML, FillCharacter returns that character, and FillCharacterIndex is the number of characters of the returned text ahead of the place the repeats go. The returned text carries no copy of the repeats, so only a renderer that knows the cell width can expand them, and width-less output such as the TEXT function or plain display strings simply leave the fill out; all three stay valid immediately after GetDisplayValue returns
StringToHTML escapes ampersands, angle brackets and double quotes into entities and turns CR/LF pairs and lone CR characters into <br>, so previously formatted text can be embedded directly; ISRightHAlign reports True for Boolean, empty, null, integral, floating-point and currency Variants and False for text, matching the natural horizontal alignment Excel applies for those value types
Windows raw varDate conversion keeps the platform Variant/OLE path; the FPC branch observes its existing time-only or general date/time conversion
TXLSCalcEvalState.ResourceObserver (handler type TXLSCalcResourceObserver, receiving cumulative reserved allocation bytes and work units as Int64 values) supplies work and allocation reservations for guarded formula consumers, with ordinary behaviour unchanged when no observer is assigned; the observer and reference-date hooks do not automatically impose workbook-wide memory limits
TXLSCalcEvalState.ReserveAllocation(ABytes) checks a nonnegative reservation and tells the observer; False reports an exhausted or cancelled state, and callback exceptions propagate
TXLSCalcEvalState.ReserveValueCopy(AValue) reserves a conservative copy envelope for supported scalar values and one- or two-dimensional arrays; False also reports unsupported by-reference, nested-array or element forms
TXLSCalcEvalState.ResourceReferenceDate sets the stable date used by guarded formula evaluation; configure the evaluation state before assigning the observer and reference date, because Configure resets both hooks
Guarded evaluation drives its budget through the state: BeginFormula and EndFormula bracket a compiled formula's evaluation and track recursion depth, with BeginFormula refusing entry once the depth ceiling is reached, ConsumeStep and ConsumeSteps(ACount) charge work through the observer and return False for a negative count, an exhausted step budget or a latched limit, IsCancelled reads the shared cancel flag and MarkResourceLimit latches the exhausted state so later step or value reservations fail without touching the model
Evaluation caches are addressed by change identifier: TryGetFormulaValue, StoreFormulaValue and ClearFormulaValue handle ordinary compiled formulas, whilst TryGetArrayValue and StoreArrayValue do the same for array formulas; FormulaCount, ArrayCount and MaxArrayBytes report the live cache sizes and the configured allocation envelope, AllowUnsafeFormulaCallbacks and ProjectBlankResults echo the options that were configured, and ResourceLimitExceeded reports whether the limit has already been latched; Clear resets hooks, observed formulas and cached entries together
Related filter storage is documented under TXLSXAutoFilterColumn and TXLSXAutoFilterColumns