Click or drag to resize

SortLevel Class

Represents sort settings for a single sort level.
Inheritance Hierarchy

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public sealed class SortLevel

The SortLevel type exposes the following members.

Public propertyColumnRowIndex

Gets or sets the column (or the row, if LeftToRight is ) index relative to the Range that this sort level applies to.

Value is equal to or greater than zero and less than Width (or Height, if LeftToRight is ) of the Range.

Public propertyComparison

Gets or sets the comparison method that compares two ExcelCells.

Default value is default comparison method based on the settings of this sort level.

Public propertyCustomList

Gets the custom list by which order of items to sort by.

If Descending is set to , then sorting will be performed based on the reverse order of items.

Public propertyDescending

Gets or sets a value indicating whether to sort the values in the descending order.

Default value is .


Following methods shows various ways to specify and apply a SortState to a range of cells.

static void Sort1(ExcelWorksheet worksheet)
    // Specify and apply Sort using less-verbose, fluent, but less understandable interface.
    worksheet.Cells.GetSubrange("A1", "D20").Sort(true).
        By(1, true).
        By(2, "Female", "Male").

static void Sort2(ExcelWorksheet worksheet)
    // Specify and apply Sort using more verbose, but more understandable interface.
    var sort = worksheet.Cells.GetSubrange("A1", "D20").Sort(true);


    var level2 = sort.Levels.Add(1);
    level2.Descending = true;

    var level3 = sort.Levels.Add(2);
    level3.SetCustomList("Female", "Male");


static void Sort3(ExcelWorksheet worksheet)
    // Specify and apply Filter using less-verbose, fluent and understandable interface (with help of C# 4.0 named arguments).
    worksheet.Cells.GetSubrange("A1", "D20").Sort(active: true).
        By(columnRowIndex: 0).
        By(columnRowIndex: 1, descending: true).
        By(columnRowIndex: 2, customList: new string[] { "Female", "Male" }).
See Also