ExcelScript.SortField interface

Stellt eine Bedingung in einem Sortiervorgang dar.

Eigenschaften

ascending

Gibt an, ob die Sortierung auf aufsteigende Weise erfolgt.

color

Gibt die Farbe an, die das Ziel der Bedingung ist, wenn die Sortierung auf Schriftart oder Zellenfarbe erfolgt.

dataOption

Stellt weitere Sortieroptionen für dieses Feld dar.

icon

Gibt das Symbol an, das das Ziel der Bedingung ist, wenn sich die Sortierung auf dem Symbol der Zelle befindet.

key

Gibt die Spalte (oder Zeile, abhängig von der Sortierausrichtung) an, für die die Bedingung gilt. Wird als Offset von der ersten Spalte (oder Zeile) dargestellt.

sortOn

Gibt den Sortiertyp dieser Bedingung an.

subField

Gibt das Unterfeld an, bei dem es sich um den Namen der Zieleigenschaft eines Rich-Werts handelt, nach dem sortiert werden soll.

Details zur Eigenschaft

ascending

Gibt an, ob die Sortierung auf aufsteigende Weise erfolgt.

ascending?: boolean;

Eigenschaftswert

boolean

color

Gibt die Farbe an, die das Ziel der Bedingung ist, wenn die Sortierung auf Schriftart oder Zellenfarbe erfolgt.

color?: string;

Eigenschaftswert

string

Beispiele

/**
 * This script sorts a range based on the color of the cells.
 * It brings all red cells to the top of the range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range (A1:D8) to sort from the current worksheet.
  const worksheet = workbook.getActiveWorksheet();
  const rangeToSort = worksheet.getRange("A1:D8");

  // Create a SortField for color sorting.
  // This sorts the rows based on the fill color of each row's cell in the first column.
  let colorSort: ExcelScript.SortField = {
    ascending: true,
    color: "FF0000", /* red */
    key: 0,
    sortOn: ExcelScript.SortOn.cellColor
  };

  // Apply the SortField to the range.
  rangeToSort.getSort().apply([colorSort]);
}

dataOption

Stellt weitere Sortieroptionen für dieses Feld dar.

dataOption?: SortDataOption;

Eigenschaftswert

Beispiele

/**
 * This script sorts a table based on the values in column 1.
 * If the text of a column-1 value can be treated as a number, 
 * it will be sorted in numerical order, rather than Unicode order
 * (so 123 will come before 12.3).
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table on the current worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const table = currentSheet.getTables()[0];

  // Create the sorting parameters.
  const countSortField: ExcelScript.SortField = {
    key: 1,
    ascending: true,
    dataOption: ExcelScript.SortDataOption.textAsNumber
  };

  // Apply the sort to the table.
  const sort = table.getSort();
  sort.apply([countSortField]);
}

icon

Gibt das Symbol an, das das Ziel der Bedingung ist, wenn sich die Sortierung auf dem Symbol der Zelle befindet.

icon?: Icon;

Eigenschaftswert

key

Gibt die Spalte (oder Zeile, abhängig von der Sortierausrichtung) an, für die die Bedingung gilt. Wird als Offset von der ersten Spalte (oder Zeile) dargestellt.

key: number;

Eigenschaftswert

number

Beispiele

/**
 * 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 rows. */
        ExcelScript.SortOrientation.rows
    );
}

sortOn

Gibt den Sortiertyp dieser Bedingung an.

sortOn?: SortOn;

Eigenschaftswert

subField

Gibt das Unterfeld an, bei dem es sich um den Namen der Zieleigenschaft eines Rich-Werts handelt, nach dem sortiert werden soll.

subField?: string;

Eigenschaftswert

string