ExcelScript.TableSort interface

Manages sorting operations on Table objects.

Methods

apply(fields, matchCase, method)

Perform a sort operation.

clear()

Clears the sorting that is currently on the table. While this doesn't modify the table's ordering, it clears the state of the header buttons.

getFields()

Specifies the current conditions used to last sort the table.

getMatchCase()

Specifies if the casing impacts the last sort of the table.

getMethod()

Represents the Chinese character ordering method last used to sort the table.

reapply()

Reapplies the current sorting parameters to the table.

Method Details

apply(fields, matchCase, method)

Perform a sort operation.

apply(
            fields: SortField[],
            matchCase?: boolean,
            method?: SortMethod
        ): void;

Parameters

fields

ExcelScript.SortField[]

The list of conditions to sort on.

matchCase

boolean

Optional. Whether to have the casing impact string ordering.

method
ExcelScript.SortMethod

Optional. The ordering method used for Chinese characters.

Returns

void

Examples

/**
 * This sample creates a table from the current worksheet's used range, then sorts it based on the first column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the current worksheet.
  let selectedSheet = workbook.getActiveWorksheet();

  // Create a table with the used cells.
  let usedRange = selectedSheet.getUsedRange();
  let newTable = selectedSheet.addTable(usedRange, true);

  // Sort the table using the first column.
  newTable.getSort().apply([{ key: 0, ascending: true }]);
}

clear()

Clears the sorting that is currently on the table. While this doesn't modify the table's ordering, it clears the state of the header buttons.

clear(): void;

Returns

void

getFields()

Specifies the current conditions used to last sort the table.

getFields(): SortField[];

Returns

getMatchCase()

Specifies if the casing impacts the last sort of the table.

getMatchCase(): boolean;

Returns

boolean

getMethod()

Represents the Chinese character ordering method last used to sort the table.

getMethod(): SortMethod;

Returns

reapply()

Reapplies the current sorting parameters to the table.

reapply(): void;

Returns

void