Calc Guide
Listing 16 demonstrates a more advanced filter that filters two
columns and uses regular expressions. I noticed some unexpected
behavior while working with Listing 16. Although you can create a
filter descriptor using any sheet cell range, the filter applies to the
entire sheet.
Listing 16. A simple sheet filter using two columns.
Sub SimpleSheetFilter_2()
Dim oSheet ' Sheet to filter.
Dim oRange ' Range to be filtered.
Dim oFilterDesc ' Filter descriptor.
Dim oFields(1) As New com.sun.star.sheet.TableFilterField
oSheet = ThisComponent.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("E12:G19")
REM If argument is True, creates an
REM empty filter descriptor.
oFilterDesc = oRange.createFilterDescriptor(True)
REM Setup a field to view cells with content that
REM start with the letter b.
With oFields(0)
.Field = 0 ' Filter column A.
.IsNumeric = False ' Use a string, not a number.
.StringValue = "b.*" ' Everything starting with b.
.Operator = com.sun.star.sheet.FilterOperator.EQUAL
End With
REM Setup a field that requires both conditions and
REM this new condition requires a value greater or
REM equal to 70.
With oFields(1)
.Connection = com.sun.star.sheet.FilterConnection.AND
.Field = 5 ' Filter column F.
.IsNumeric = True ' Use a number
.NumericValue = 70 ' Values greater than 70
.Operator = com.sun.star.sheet.FilterOperator.GREATER_EQUAL
End With
oFilterDesc.setFilterFields(oFields())
oFilterDesc.ContainsHeader = False
oFilterDesc.UseRegularExpressions = True
oSheet.filter(oFilterDesc)
End Sub
Chapter 13 Calc as a Simple Database 371