From Apache OpenOffice Wiki
Jump to: navigation, search

A object is created using the createFilterDescriptor() method from the range's interface to filter data in a cell range. After applying the settings to the descriptor, it is passed to the filter() method.

If true is passed as a bEmpty parameter to createFilterDescriptor(), the returned descriptor contains default values for all settings. If false is passed and the cell range is a database range that has a stored filter operation, the settings for that filter are used.


The interface is used to set the filter criteria as a sequence of elements. The struct describes a single condition and contains the following members:

  • Connection has the values AND or OR, and specifies how the condition is connected to the previous condition in the sequence. For the first entry, Connection is ignored.
  • Field is the number of the field that the condition is applied to.
  • Operator is the type of the condition, such as EQUAL or GREATER
  • IsNumeric selects a numeric or textual condition.
  • NumericValue contains the value that is used in the condition if IsNumeric is true.
  • StringValue contains the text that is used in the condition if IsNumeric is false.

Additionally, the filter descriptor contains a interface for settings that affect the whole filter operation.

If the property CopyOutputData is true, the data that matches the filter criteria is copied to a cell range in the document that starts at the position specified by the OutputPosition property. Otherwise, the rows that do not match the filter criteria are filtered (hidden) in the original cell range.

The following example filters the range that is in the variable xRange for values greater or equal to 1998 in the second column:

 // --- filter for second column >= 1998 --- xFilter = (
     UnoRuntime.queryInterface(, xRange); xFilterDesc =
     xFilter.createFilterDescriptor(true);[] aFilterFields =
 aFilterFields[0] = new;
 aFilterFields[0].Field = 1;
 aFilterFields[0].IsNumeric = true;
 aFilterFields[0].Operator =;
 aFilterFields[0].NumericValue = 1998;
 xFilterDesc.setFilterFields(aFilterFields); xFilterProp = (
     UnoRuntime.queryInterface(, xFilterDesc);
 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));

The interface is used to create a filter descriptor from criteria in a cell range in the same manner as the "Advanced Filter" dialog. The interface must be queried from the range that contains the conditions, and the interface of the range to be filtered must be passed to the createFilterDescriptorByObject() call.

The following example performs the same filter operation as the example before, but reads the filter criteria from a cell range:

 // --- do the same filter as above, using criteria from a cell range --- xCritRange = xSheet.getCellRangeByName("B27:B28"); xCritData = (
     UnoRuntime.queryInterface(, xCritRange);
 Object[][] aCritValues = {{"Year"}, {">= 1998"}};
 xCritData.setDataArray(aCritValues); xCriteria = (
     UnoRuntime.queryInterface(, xCritRange);
 xFilterDesc = xCriteria.createFilterDescriptorByObject(xFilter);
 if (xFilterDesc != null)
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages