ExcelScript.RangeSort interface
Manages sorting operations on Range
objects.
Methods
apply(fields, match |
Perform a sort operation. |
Method Details
apply(fields, matchCase, hasHeaders, orientation, method)
Perform a sort operation.
apply(
fields: SortField[],
matchCase?: boolean,
hasHeaders?: boolean,
orientation?: SortOrientation,
method?: SortMethod
): void;
Parameters
- fields
The list of conditions to sort on.
- matchCase
-
boolean
Optional. Whether to have the casing impact string ordering.
- hasHeaders
-
boolean
Optional. Whether the range has a header.
- orientation
- ExcelScript.SortOrientation
Optional. Whether the operation is sorting rows or columns.
- method
- ExcelScript.SortMethod
Optional. The ordering method used for Chinese characters.
Returns
void
Examples
/**
* This script sorts the used range of the current worksheet.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the used range of the current worksheet.
const activeRange = workbook.getActiveWorksheet().getUsedRange();
// Sort the rows in ascending order based on the last column.
activeRange.getSort().apply(
[{
ascending: true,
key: activeRange.getColumnCount() - 1
}],
false, /* Don't match case. */
true, /* Treat the first row as a header row. */
ExcelScript.SortOrientation.rows
);
}