Calc how to sort columns at lines

Hello! I have a simple spreadsheet with 100 lines. Each line has 27 columns (A to C are some codes, D to Z are names). 1st line is labels “code1, code2, code3, name1, name2, name3…”.

image description

How do I can sort this to make 1+2:

  1. all codes must be in crescent numeric order

  2. all names must be in alphabetic crescent order

[1] is very eazy, I select all data, A1 to Z100, Data->Sort by criteria A/B/C, with labels.

But HOW to classify the 24 columns of each line?
Not by the 1st line. All names at each line must be alphabetically sorted!

If I select a single partial line from D3 to Z3, LibreOffice popups asking to extend selection (annoyance).
I change then all options to sort by column, without labels, and then I can sort these columns of that line 3.
But LO can not repeat/redo this operation (menu is disabled). Then I select D4 to Z4, and again that nuisance popups asking about extending selection and worse, all sort criteria is lost and I must set it again.

Sorry, but somebody know how to do it in a nice and easy way?

Thanks, yours,
Daniel, from Brazil

LO calc sort problem.ods

Hallo

It’s doable by 5 simple lines of code:

def sort_rows_of_selection_reverse():
    doc = XSCRIPTCONTEXT.getDocument()
    sel = doc.CurrentSelection
    data = sel.DataArray
    out = tuple((tuple(sorted(row,reverse=True)) for row in data))
    sel.DataArray = out

store it in some_filename.py into path <your LO-userconfig>/Scripts/python/

and run it after selecting D2:Z100

Thanks! It works… but not so good, if some cell is empty, it get before that one with text. Maybe a solution at a full block.
I found a LibO Basic to do what I need (sorry LO but VBS/MS-Office is far better and easier!).

I continue searching for a solution like “press ctrl+key” to repeat sort operation as done before.
Is ther some configuration for this? Like “my preferences” options?

Thanks!

you want empties first ?

    out = tuple((tuple(sorted(row, key=lambda x: x or 'zzzzzz',reverse=True)) for row in data))