SortState Class
Represents sort settings and provides sort functionality.
- Inheritance:
- System.ObjectSortState
Remarks
Use Sort(Boolean) method to create or get a SortState instance.
Active SortState is stored in the parent worksheet (Sort) and is loaded from and saved to XLSX file.
Properties
CaseSensitive
Gets or sets a value indicating whether the sort is case-sensitive.
Default value is false.
Property Value
- System.Boolean
true if the sort is case-sensitive; otherwise, false.
LeftToRight
Gets or sets a value indicating whether to sort from left to right (whether to sort columns instead of rows).
Default value is false.
Property Value
- System.Boolean
true to sort from left to right (to sort columns); otherwise, false to sort from top to bottom (to sort rows).
Exceptions
- System.InvalidOperationException
Sorting columns is not supported for the current sort state.
Levels
Gets the sort levels.
public SortLevelCollection Levels { get; }
Public ReadOnly Property Levels As SortLevelCollection
Property Value
The sort levels.
Range
Gets the range to sort.
Property Value
The range to sort.
Methods
Apply()
Remarks
Hidden (Hidden is true) rows (or columns, if LeftToRight is true) won't be sorted.
Exceptions
- System.InvalidOperationException
Sort range contains merged cells.
By(Int32)
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range).
public SortState By(int columnRowIndex)
Public Function By(columnRowIndex As Integer) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, Boolean)
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order to sort by.
public SortState By(int columnRowIndex, bool descending)
Public Function By(columnRowIndex As Integer, descending As Boolean) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
descending
- System.Boolean
true to sort the values in the descending order; otherwise, false.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, Boolean, IEnumerable<String>)
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order and custom list by which order of items to sort by.
public SortState By(int columnRowIndex, bool descending, IEnumerable<string> customList)
Public Function By(columnRowIndex As Integer, descending As Boolean, customList As IEnumerable(Of String)) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
descending
- System.Boolean
true to sort the values in the descending order; otherwise, false.
customList
- System.Collections.Generic.IEnumerable<System.String>
The custom list by which order of items to sort by.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, Boolean, String[])
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order and custom list by which order of items to sort by.
public SortState By(int columnRowIndex, bool descending, params string[] customList)
Public Function By(columnRowIndex As Integer, descending As Boolean, ParamArray customList As String()) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
descending
- System.Boolean
true to sort the values in the descending order; otherwise, false.
customList
- System.String[]
The custom list by which order of items to sort by.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, IEnumerable<String>)
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified custom list by which order of items to sort by.
public SortState By(int columnRowIndex, IEnumerable<string> customList)
Public Function By(columnRowIndex As Integer, customList As IEnumerable(Of String)) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
customList
- System.Collections.Generic.IEnumerable<System.String>
The custom list by which order of items to sort by.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, Comparison<ExcelCell>)
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified comparison method to sort by.
public SortState By(int columnRowIndex, Comparison<ExcelCell> comparison)
Public Function By(columnRowIndex As Integer, comparison As Comparison(Of ExcelCell)) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
comparison
- System.Comparison<ExcelCell>
The comparison method to sort by.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
By(Int32, String[])
Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified custom list by which order of items to sort by.
public SortState By(int columnRowIndex, params string[] customList)
Public Function By(columnRowIndex As Integer, ParamArray customList As String()) As SortState
Parameters
columnRowIndex
- System.Int32
The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.
customList
- System.String[]
The custom list by which order of items to sort by.
Returns
Exceptions
- System.ArgumentOutOfRangeException
columnRowIndex
is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.
- System.ArgumentException
Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.
ToString()
Returns a System.String that represents this SortState instance.
Returns
- System.String
A System.String that represents this SortState instance.
Overrides
Remarks
This method should be used primarily for debugging purposes and should be considered volatile (format of its return value might change in future versions).