Macros/Calc/ba026

Summary
This page provides a LibreOffice Basic macro procedure that creates a simple standard filter. It is an example drawn from Chapter 13 ("Calc as a Database") of the 7.0 Calc Guide.

Description
In a macro, filtering a data range is performed by calling the filter method either on the range or the sheet in which the range is contained. Like a sort descriptor, a filter descriptor contains the filter settings for the current sheet, such as whether the first row or column in the sheet contains headers which should not be filtered. A filter descriptor can be generated by calling the createFilterDescriptor method on a sheet or on a cell range:
 * createFilterDescriptor( Empty )
 * Creates a filter descriptor. If the boolean flag Empty is set to TRUE, then an empty filter descriptor is created. If Empty is FALSE, then the descriptor is filled with the previous settings of the current object (such as a database range).

As with sort descriptors, filter descriptors can be created using this method, then modified and passed as an argument to the filter method. The macro below demonstrates this process by creating a simple standard filter for the first sheet in a document.

Code
This [[Media:Create_standard_filter_with_macro.ods|Calc spreadsheet]] contains the above LibreOffice Basic code.