[Solved] FilterDescriptor.setFilterFields3 method broken after LibreOffice v7.1

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
wrighch
Posts: 2
Joined: Mon Feb 20, 2023 1:06 pm

[Solved] FilterDescriptor.setFilterFields3 method broken after LibreOffice v7.1

Post by wrighch »

I have a Calc macro that has worked well for years and continues to work using Libreoffice v7.1.1.2 on Windows 7-10-11. It fails after I upgraded to LibreOffice v7.4.4.2. The macro filters a Database Range on a Sheet by creating a complex FilterDescriptor that contains multiple TableFilterFields. The macro uses TableFilterField3 structures because only those structures allow a TableFilterField to specify multiple values for a field in the same way that an AutoFilter allows a user to select multiple values for a column. So, in addition to using TableFilterField3 structures for the fields to be filtered, the macro also must use the setFilterFields3 method when imposing the array of TableFilterField3 structures on the FilterDescriptor.

As I said, the macro has worked for years on previous versions of LibreOffice. But in v7.4.4.2 (and v7.5) the setFilterField3 method appears to improperly interpret the FilterFieldValues in the TableFilterField Values Array-- always assigning the IsNumeric property as TRUE even when the macro explicitly assigns FALSE. Essentially, the macro continues to properly filter multiple numeric values for a field, but fails when trying to select multiple String values for the field.

I have retrieved and examined the FilterDescriptor imposed by AutoFilter and, it is identical to the one my macros imposes when the macro is instructed to create a filter comprising purely numeric values. Further, the array of TableFilterFields3 items that my macro constructs when instructed to include one or more String values is identical to the one that AutoFilter produces for the same conditions. But when I subsequently retrieve and examine the FilterDescriptor imposed by setFilterFields3 for the String case, all FilterFieldValues are reported as Numeric.

Can anyone offer any suggestions?
Last edited by Hagar Delest on Mon Feb 20, 2023 10:03 pm, edited 1 time in total.
Reason: tagged solved.
Charlie, LibreOffice v7.4, Windows-11
wrighch
Posts: 2
Joined: Mon Feb 20, 2023 1:06 pm

Re: FilterDescriptor.setFilterFields3 method broken after LibreOffice v7.1

Post by wrighch »

No sooner did I post my question, than I found a solution that works.

Apparently, sometime after LibreOffice v7.1, the definition of com.sun.star.sheet.FilterFieldValue was modified to add two new Properties: FilterType and ColorValue (both LONG INTEGER). For each value, in addition to properly setting the IsNumeric property, you MUST also specify FilterType as either com.sun.star.sheet.FilterFieldType.NUMERIC or com.sun.star.sheet.FilterFieldType.STRING. When I did that, my filter worked without other changes. See https://api.libreoffice.org/docs/idl/re ... dType.html for the enumeration of FilterType. I have not (yet) pursued filter by color or use of some of the other enumeration values listed in the link I provided.
Charlie, LibreOffice v7.4, Windows-11
Post Reply