Link Search Menu Expand Document

SSpread.Sort Method

Explanation Sorts the specified data.
Call format Sort(col, row, col2, row2, sortby [, sortkeys, sortkeyorders])
Return value $TRUE if successful, $FALSE otherwise
Arguments col First column number in the sort range
row Row number at the beginning of the sort range
col2 Last column number in the sort range
row2 Last row number in the sort range
sortby Sort type
Specify the following values.
Constant Value Description
$SortByRow 0 Sort rows
$SortByCol 1 Sort columns
sortkeys An array object (optional) that indicates the column / row number to be used as the sort key.
sortkeyorders An array object that indicates the sort order (optional)
Specify the following values.
Value Description
1 Sort in ascending order
2 Sort in descending order

For sortkeys and sortkeyorders, specify an Array Object that has the information required for sorting. The smaller the index of the array, the higher the priority of the sort keys. By making the indexes the same, the combination of the row / column number can be set to be the key for sorting and the sorting order (ascending / descending order). If sortkeys and sortkeyorders are omitted, the values of the SortKey property and SortKeyOrder property are used.
Exception EXT-1 The argument of Sort is invalid
Example of use
    /* Example of using SortKey and SortKeyOrder properties */
    SortKey(0) = 2; /* 1st key 2nd column */
    SortKey(1) = 3; /* 2nd key 3rd column */
    SortKey(2) = 4; /* 3rd key 4th column */
    SortKeyOrder(0) = $SortKeyOrderAscending;  /* 1st key ascending order */
    SortKeyOrder(1) = $SortKeyOrderDescending; /* 2nd key descending order */
    SortKeyOrder(2) = $SortKeyOrderDescending; /* 3rd key descending order */
    Sort(1, -1, 4, -1, $SortByRow); /* Sort all rows in columns 1 to 4 */
    
    /* Example of specifying all with arguments (processing content is the same as above) */
    var sortkeys = new Number[3];
    var sortorder = new Number[3];
    sortkeys[0] = 2;
    sortkeys[1] = 3;
    sortkeys[2] = 4;
    sortorder[0] = 1;
    sortorder[1] = 2;
    sortorder[2] = 2;
    Sort(1, -1, 4, -1, $SortByRow, sortkeys, sortorder);
    
Related item SortKey, SortKeyOrder properties