Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is code that does what you asked.

Sub ModifyFilter
    oDoc = ThisComponent
    oRanges = oDoc.getPropertyValue("DatabaseRanges")
    oRange = oRanges.getByName("data1")
    oFilterDesc = oRange.getFilterDescriptor()
    aFilterFields = oFilterDesc.getFilterFields()
    With aFilterFields(0)
        .StringValue = "b"
    End With
    oFilterDesc.setFilterFields(aFilterFields)
    oRange.refresh()
End Sub

Sample file: modify autofilter.ods

Documentation is at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filtering. However, I found that it did not cover all of the filter interfaces, for example TableFilterField3 for filtering multiple values. Use an introspection tool such as MRI or XrayTool to explore these options.

Here is code that does what you asked.asked in the comment.

Sub ModifyFilter
    oDoc = ThisComponent
    oRanges = oDoc.getPropertyValue("DatabaseRanges")
    oRange = oRanges.getByName("data1")
    oFilterDesc = oRange.getFilterDescriptor()
    aFilterFields = oFilterDesc.getFilterFields()
    With aFilterFields(0)
        .StringValue = "b"
    End With
    oFilterDesc.setFilterFields(aFilterFields)
    oRange.refresh()
End Sub

Sample file: modify autofilter.ods

Documentation is at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filtering. However, I found that it did not cover all of the filter interfaces, for example TableFilterField3 for filtering multiple values. Use an introspection tool such as MRI or XrayTool to explore these options.

Here is code that does what you asked in the comment.

Sub ModifyFilter
    oDoc = ThisComponent
    oRanges = oDoc.getPropertyValue("DatabaseRanges")
    oRange = oRanges.getByName("data1")
    oFilterDesc = oRange.getFilterDescriptor()
    aFilterFields = oFilterDesc.getFilterFields()
    With aFilterFields(0)
        .StringValue = "b"
    End With
    oFilterDesc.setFilterFields(aFilterFields)
    oRange.refresh()
End Sub

Sample file: modify autofilter.ods

Documentation is at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filtering.

However, I found that it the documentation did not cover describe all of the filter interfaces, for example TableFilterField3 for filtering multiple values. Use an introspection tool such as MRI or XrayTool to explore these options.