On 8/21/25 06:46, Regina Henschel wrote:
Hi all,

LibreOffice can sort texts in "natural sort" kind in database ranges in Calc. That is an order K1, K2, K14, K107 instead of the alphanumeric order K1, K107, K14, K2. But LibreOffice does not write/read to ODF, that a database range uses this kind of sorting. I want to implement this.

Problem A: The according ODF attribute is table:embedded-number-behavior (19.628, part 3 ODF 1.4). https://docs.oasis-open.org/office/OpenDocument/v1.4/cs01/part3-schema/OpenDocument-v1.4-cs01-part3-schema.html#attribute-table_embedded-number-behavior
It has the values 'alpha-numeric', 'double', and 'integer'.

The according LibreOffice attribute in core is
bool bNaturalSort
in struct ScSortParam.

Thus ODF has three kinds and LO has two kinds.
From my tests I guess, that bNaturalSort=true corresponds to value 'double'.

Yes. In fact I remember this feature since I worked on this. You can still see the spec document I wrote for this feature back in 2005: https://www.openoffice.org/specs/calc/ease-of-use/natural_sort_algorithm.sxw.

It should be fairly trivial to implement the integer mode since all you have to change is to not allow the decimal separator to be parsed as a digit character. Here

https://git.libreoffice.org/core/+/refs/heads/master/sc/source/core/data/table3.cxx#119

is where the code retrieves the decimal separator character for the current locale and plug that into the token parser. Passing an empty string in lieu of that may be enough to implement the integer mode (in theory.. please test this!).  Then you can switch that bNaturalSort boolean flag to a tri-state flag and map that to the UNO API.


Problem B: There exists no UNO property for natural sort.
Can I simply add it to css.sheet.SheetSortDescriptor2? As boolean or as enum?

IIRC we are not supposed to use enum in the UNO API since the enum type cannot be extended once defined.  Instead, we are to use a group of integer constants to simulate an enum type, then we can append new values to that group as needed.

Kohei

Reply via email to