HotXLS Docs

ApplyAutoFilter method

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.
Use IXLSWorksheet.AutoFilterColumns 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