public final class SortState extends Object
Use CellRange.sort(boolean)
method to create or get a SortState
instance.
Active SortState
is stored in the parent worksheet (ExcelWorksheet.getSort()
) and is loaded from and saved to XLSX file.
public static void sort1(ExcelWorksheet worksheet) {
// Specify and apply Sort using less-verbose, fluent, but less understandable interface.
worksheet.getCells().getSubrange("A1", "D20").sort(true).
by(0).
by(1, true).
by(2, "Female", "Male").
apply();
}
public static void sort2(ExcelWorksheet worksheet) {
// Specify and apply Sort using more verbose, but more understandable interface.
SortState sort = worksheet.getCells().getSubrange("A1", "D20").sort(true);
sort.getLevels().add(0);
SortLevel level2 = sort.getLevels().add(1);
level2.setDescending(true);
SortLevel level3 = sort.getLevels().add(2);
level3.setCustomList("Female", "Male");
sort.apply();
}
Modifier and Type | Method and Description |
---|---|
void |
apply()
|
SortState |
by(int columnRowIndex)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() is true ) with the specified index (relative to the range ). |
SortState |
by(int columnRowIndex,
boolean descending)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() is true ) with the specified index (relative to the range ) and with the specified order to sort by. |
SortState |
by(int columnRowIndex,
boolean descending,
Iterable<String> customList)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() 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. |
SortState |
by(int columnRowIndex,
boolean descending,
String... customList)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() 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. |
SortState |
by(int columnRowIndex,
Comparator<ExcelCell> comparator)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() is true ) with the specified index (relative to the range ) and with the specified comparison method to sort by. |
SortState |
by(int columnRowIndex,
Iterable<String> customList)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() is true ) with the specified index (relative to the range ) and with the specified custom list by which order of items to sort by. |
SortState |
by(int columnRowIndex,
String... customList)
Adds a
SortLevel applied to a column (or a row, if isLeftToRight() is true ) with the specified index (relative to the range ) and with the specified custom list by which order of items to sort by. |
SortLevelCollection |
getLevels()
Gets the sort levels.
|
CellRange |
getRange()
Gets the range to sort.
|
boolean |
isCaseSensitive()
Gets a value indicating whether the sort is case-sensitive.
|
boolean |
isLeftToRight()
Gets a value indicating whether to sort from left to right (whether to sort columns instead of rows).
|
void |
setCaseSensitive(boolean caseSensitive)
Sets a value indicating whether the sort is case-sensitive.
|
void |
setLeftToRight(boolean value)
Sets a value indicating whether to sort from left to right (whether to sort columns instead of rows).
|
String |
toString()
Returns a
String that represents this SortState instance. |
public void apply()
range
based on this SortState
settings.
Hidden (ExcelColumnRowBase.isHidden()
is true
) rows (or columns, if isLeftToRight()
is true
) won't be sorted.
IllegalStateException
- Sort range contains merged cells.public SortState by(int columnRowIndex)
SortLevel
applied to a column (or a row, if isLeftToRight()
is true
) with the specified index (relative to the range
).columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, boolean descending)
SortLevel
applied to a column (or a row, if isLeftToRight()
is true
) with the specified index (relative to the range
) and with the specified order to sort by.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.descending
- true
to sort the values in the descending order; otherwise, false
.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, boolean descending, Iterable<String> customList)
SortLevel
applied to a column (or a row, if isLeftToRight()
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.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.descending
- true
to sort the values in the descending order; otherwise, false
.customList
- The custom list by which order of items to sort by.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, boolean descending, String... customList)
SortLevel
applied to a column (or a row, if isLeftToRight()
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.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.descending
- true
to sort the values in the descending order; otherwise, false
.customList
- The custom list by which order of items to sort by.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, Comparator<ExcelCell> comparator)
SortLevel
applied to a column (or a row, if isLeftToRight()
is true
) with the specified index (relative to the range
) and with the specified comparison method to sort by.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.comparator
- The comparison method to sort by.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, Iterable<String> customList)
SortLevel
applied to a column (or a row, if isLeftToRight()
is true
) with the specified index (relative to the range
) and with the specified custom list by which order of items to sort by.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.customList
- The custom list by which order of items to sort by.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortState by(int columnRowIndex, String... customList)
SortLevel
applied to a column (or a row, if isLeftToRight()
is true
) with the specified index (relative to the range
) and with the specified custom list by which order of items to sort by.columnRowIndex
- The index of a column (or a row, if isLeftToRight()
is true
) relative to the range
that an added SortLevel
applies to.customList
- The custom list by which order of items to sort by.SortState
to specify additional sort levels or to apply sort.IndexOutOfBoundsException
- columnRowIndex
is less than zero or is equal to or greater than width
(or height
, if isLeftToRight()
is true
) of the range
.IllegalArgumentException
- Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.public SortLevelCollection getLevels()
public CellRange getRange()
public boolean isCaseSensitive()
Gets a value indicating whether the sort is case-sensitive.
Default value is false
.
true
if the sort is case-sensitive; otherwise, false
.public boolean isLeftToRight()
Gets a value indicating whether to sort from left to right (whether to sort columns instead of rows).
Default value is false
.
true
to sort from left to right (to sort columns); otherwise, false
to sort from top to bottom (to sort rows).public void setCaseSensitive(boolean caseSensitive)
Sets a value indicating whether the sort is case-sensitive.
Default value is false
.
caseSensitive
- true
if the sort is case-sensitive; otherwise, false
.public void setLeftToRight(boolean value)
Sets a value indicating whether to sort from left to right (whether to sort columns instead of rows).
Default value is false
.
value
- true
to sort from left to right (to sort columns); otherwise, false
to sort from top to bottom (to sort rows).IllegalStateException
- Sorting columns is not supported for the current sort state.© GemBox d.o.o. — All rights reserved.