Calc Guide

.Field = 5
REM Compare using a numeric or a string?
.IsNumeric = True
REM The NumericValue property is used
REM because .IsNumeric = True from above.
.NumericValue = 80
REM If IsNumeric was False, then the
REM StringValue property would be used.
REM .StringValue = "what ever"
REM Valid operators include EMPTY, NOT_EMPTY, EQUAL,
REM NOT_EQUAL, GREATER, GREATER_EQUAL, LESS,
REM LESS_EQUAL, TOP_VALUES, TOP_PERCENT,
REM BOTTOM_VALUES, and BOTTOM_PERCENT
.Operator = com.sun.star.sheet.FilterOperator.GREATER_EQUAL
End With
REM The filter descriptor supports the following
REM properties: IsCaseSensitive, SkipDuplicates,
REM UseRegularExpressions,
REM SaveOutputPosition, Orientation, ContainsHeader,
REM CopyOutputData, OutputPosition, and MaxFieldCount.
oFilterDesc.setFilterFields(oFields())
oFilterDesc.ContainsHeader = True
oSheet.filter(oFilterDesc)
End Sub
When a filter is applied to a sheet, it replaces any existing filter for the sheet. Setting
an empty filter in a sheet will therefore remove all filters for that sheet (see Listing
15).
Listing 15. Remove the current sheet filter.
Sub RemoveSheetFilter()
Dim oSheet ' Sheet to filter.
Dim oFilterDesc ' Filter descriptor.
oSheet = ThisComponent.getSheets().getByIndex(0)
oFilterDesc = oSheet.createFilterDescriptor(True)
oSheet.filter(oFilterDesc)
End Sub
Listing 16 demonstrates a more advanced filter that filters two columns and uses
regular expressions. Some unexpected behavior occurred while working with Listing
16. Although you can create a filter descriptor using any sheet cell range, the filter
applies to the entire sheet.
Chapter 13 Calc as a Simple Database 325