Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #28693
    spiros
    Participant

    This can be an extra option in the Sort options, implemented in the following ways:

    1. On row level (as separated by columns)
    2. On delimiter level. Could be a selection box and an option for custom delimiter (supporting multi-character delimiters), I.e. [space][comma]

    How does it work? See here https://chandoo.org/wp/howto-sort-left-to-right-in-excel/ (columns only)

    #28694
    David
    Participant

    There’re different way for sorting column, such as A-Z, Z-A, 0-9, shortest – longest……
    If having sorting row feature, wish to have same options.

    #28723
    Yutaka Emura
    Keymaster

    This macro will sort (A to Z, case insensitive) by row level at the current cursor (or selected cell) line. You can use this macro to develop further for different sort criteria.

    
    function SortOneColumn( yLine )
    {
        count = document.GetColumns();
        arr = new Array(count);
        for( i = 0; i < count; ++i ) {
            s = document.GetCell( yLine, i + 1, eeCellIncludeNone );
            arr[i] = { name: s, col: i };
        }
        arr.sort( function( a, b ) {
          var nameA = a.name.toLowerCase();
          var nameB = b.name.toLowerCase();
          if( nameA < nameB ) {
            return -1;
          }
          if( nameA > nameB ) {
            return 1;
          }
          return 0;
        });
    
        bSorted = false;
        for( i = 0; i < count; ++i ) {
            if( arr[i].col != i ) {
                document.MoveColumn( arr[i].col + 1, arr[i].col + 1, i + 1 );
                bSorted = true;
                break;
            }
        }
        return bSorted;
    }
    
    yLine = document.selection.GetActivePointY( eePosLogical );
    while( SortOneColumn( yLine ) );
    

    I am not sure what you mean by 1. On delimiter level.

    #28724
    spiros
    Participant

    Imagine Excel, I mean being able to sort multiple entries left to right in one cell, separated by a delimiter, I.e. comma.
    And this procedure to the totality of selected rows.

    #28725
    Yutaka Emura
    Keymaster

    I am still not sure if I understand your question, but if you are talking about a nested CSV like this page:
    https://www.emeditor.com/text-editor-features/more-features/nested-csv/

    and if you would like to sort, for instance, “apple;banana;cherry“, you can select “Split Columns” while selecting the second column, select (None), enter the separator (a semicolon in this case), set the Sort split strings option, and select a desired sort criterion.

    #28726
    spiros
    Participant

    I tried the way you described, did not work as expected, created columns instead.

    I mean like having multiple lines like these:

    stuff, apple, banana, cherry, all
    sort, more, mpme, stuff, apple, banana, cherry, all

    Then simply running horizontal sort, and the end results being with A-Z sort

    all, apple, banana, cherry, stuff
    all, apple, banana, cherry, more, mpme, sort, stuff

    Of course it would be good if one could define the delimiter in the process.

    #28727
    Yutaka Emura
    Keymaster

    OK. I now understand your question.

    Currently, you can select a CSV mode (for instance Tab-separated, NOT Comma-separated) so that only one column should exist. Select the only one column, select the Split Columns command, then select (None), enter the Separator (Comma + Space in this case), set the Sort split strings option, and select a desired sort criterion.

    Alternatively, you can split to multiple lines by replacing Comma + Space with a newline, sort, and then replace a newline with Comma + Space to restore newlines.

    I will think about a new command in the future.

    #28742
    spiros
    Participant

    Here is an Excel implementation (so you understand better what I mean by cell-level)
    https://www.asap-utilities.com/asap-utilities-excel-tools-tip.php?tip=278&utilities=42&lang=en_us

    #28925
    Yutaka Emura
    Keymaster

    We’ve just released v22.0.901.

    – Added the Sort/Remove Duplicate split strings in Selection, Sort Columns, and Manage Columns command.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.