Sets a classic XLS AutoFilter range and applies a per-field criterion in one call
Syntax
procedure ApplyAutoFilter(ARange: WideString; Field: Integer; Criteria1: Variant); overload;
procedure ApplyAutoFilter(ARange: WideString; Field: Integer; Criteria1: Variant; Operator: XlAutoFilterOperator; Criteria2: Variant); overload;
procedure ApplyAutoFilter(ARow1, ACol1, ARow2, ACol2: Integer; Field: Integer; Criteria1: Variant); overload;
procedure ApplyAutoFilter(ARow1, ACol1, ARow2, ACol2: Integer; Field: Integer; Criteria1: Variant; Operator: XlAutoFilterOperator; Criteria2: Variant); overload;
Remarks
The string overload accepts an A1-style range such as A1:C5. The numeric overload uses 1-based row and column indexes. Field is also 1-based within the AutoFilter range
ApplyAutoFilter replaces any existing worksheet-level AutoFilter range with the supplied range, then writes the same BIFF8 field criteria records used by IXLSRange.Autofilter
A text criterion that starts with a comparison operator (>=, <=, <>, >, < or =) followed by a number, such as '>=100' or '=2.5', is stored as a number condition, so it matches numeric cells the way it does in Excel. Write the number with a period as the decimal separator. Any other text, including a bare value such as '100', is stored as a text condition
Use TXLSWorksheet.AutoFilterColumns.Find(Field) to inspect the stored per-field criteria after applying or reading a classic XLS AutoFilter
Example
Workbook := TXLSWorkbook.Create;
try
Sheet := Workbook.Sheets[1];
Sheet.ApplyAutoFilter('A1:C5', 2, '>=100');
Workbook.SaveAs('filtered.xls', xlExcel97);
finally
Workbook.Free;
end;
See Also