Calc User Sort/Fill Lists

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
eeigor
Posts: 214
Joined: Sun Apr 12, 2020 10:56 pm

Calc User Sort/Fill Lists

Post by eeigor »

See: Tools - Options - LibreOffice Calc - Sort Lists
This topic is not presented in any way on the forum ... Or am I mistaken?
Dynamic sorting by unsaved user criteria (sequence of values) entered directly on the sheet.
And the topic is very interesting, as it turned out ... I ask you to post your developments, if any, of course.

Excel Custom Lists: Demo Code (Application: .AddCustomList, .GetCustomListNum, .DeleteCustomList)
https://docs.microsoft.com/en-us/office ... customlist

Code: Select all

Sub SortRange()
    Dim nIndex&
    Application.AddCustomList ListArray:=Worksheets("1").[U4:U9]
    nIndex = Application.GetCustomListNum(Worksheets("1").Range("U4:U9").Value)
    Range("B5:K400").Sort Key1:=Range("B5"), Order1:=xlAscending _
     , Key2:=Range("C5"), Order2:=xlAscending, Header:=xlNo _
     , Orientation:=xlSortColumns, OrderCustom:=nIndex + 1  'custom list array is one based
    Application.DeleteCustomList nIndex
End Sub
+ GetCustomListContents, CustomListCount

LibreOffice Demo Code: An example of adding a new user defined sort list.

Code: Select all

Dim aUserLists$(), ListArray, sList$, nEnd%

ListArray = Array("Item1", "Item2", "Item3")
sList = Join(ListArray, ",")

Dim aUserLists$()
oSettings = createUnoService("com.sun.star.sheet.GlobalSheetSettings")
aUserLists$ = oSettings.getPropertyValue("UserLists")

nEnd = UBound(aUserLists) + 1
ReDim Preserve aUserLists(nEnd)
aUserLists(nEnd) = sList
oSettings.setPropertyValue("UserLists", aUserLists)
Last edited by MrProgrammer on Thu Mar 24, 2022 4:21 pm, edited 1 time in total.
Reason: Moved topic from Macros and UNO API forum to Code Snippets -- MrProgrammer, forum moderator
Ubuntu 18.04 LTS • LibreOffice 7.5.3.2 Community
Post Reply