Example:
# Instantiate a new Workbook object. workbook = Workbook("Book2.xlsx") # Get the workbook datasorter object. sorter = workbook.getDataSorter() # Set the first order for datasorter object. sorter.setOrder1(SortOrder.DESCENDING) # Define the first key. sorter.setKey1(0) # Set the second order for datasorter object. sorter.setOrder2(SortOrder.ASCENDING) # Define the second key. sorter.setKey2(1) # Create a cells area (range). ca = CellArea() # Specify the start row index. ca.StartRow = 0 # Specify the start column index. ca.StartColumn = 0 # Specify the last row index. ca.EndRow = 13 # Specify the last column index. ca.EndColumn = 1 # Sort data in the specified data range (A1:B14) sorter.sort(workbook.getWorksheets().get(0).getCells(), ca) # Save the excel file. workbook.save("Book1.xlsx")
Property Getters/Setters Summary | ||
---|---|---|
method | getCaseSensitive() | |
method | setCaseSensitive(value) | |
Gets and sets whether case sensitive when comparing string. | ||
method | hasHeaders() | |
method | setHasHeaders(value) | |
Represents whether the range has headers. | ||
method | getKey1() | |
method | setKey1(value) | |
Represents first sorted column index(absolute position, column A is 0, B is 1, ...). | ||
method | getKey2() | |
method | setKey2(value) | |
Represents second sorted column index(absolute position, column A is 0, B is 1, ...). | ||
method | getKey3() | |
method | setKey3(value) | |
Represents third sorted column index(absolute position, column A is 0, B is 1, ...). | ||
method | getKeys() | |
Gets the key list of data sorter.
|
||
method | getOrder1() | |
method | setOrder1(value) | |
Represents sort order of the first key. The value of the property is SortOrder integer constant. | ||
method | getOrder2() | |
method | setOrder2(value) | |
Represents sort order of the second key. The value of the property is SortOrder integer constant. | ||
method | getOrder3() | |
method | setOrder3(value) | |
Represents sort order of the third key. The value of the property is SortOrder integer constant. | ||
method | getSortAsNumber() | |
method | setSortAsNumber(value) | |
Indicates whether sorting anything that looks like a number. | ||
method | getSortLeftToRight() | |
method | setSortLeftToRight(value) | |
True means that sorting orientation is from left to right. False means that sorting orientation is from top to bottom. The default value is false. |
Method Summary | ||
---|---|---|
method | addKey(key, order) | |
Adds sorted column index and sort order.
|
||
method | addKey(key, type, order, customList) | |
Adds sorted column index and sort order with custom sort list.
|
||
method | addKey(key, order, customList) | |
Adds sorted column index and sort order with custom sort list.
|
||
method | addKey(key, order, customList) | |
Adds sorted column index and sort order with custom sort list.
|
||
method | clear() | |
Clear all settings.
|
||
method | sort() | |
Sort the data in the range.
|
||
method | sort(cells, area) | |
Sort the data of the area.
|
||
method | sort(cells, startRow, startColumn, endRow, endColumn) | |
Sorts the data of the area.
|
DataSorterKeyCollection getKeys()
boolean hasHeaders() / setHasHeaders(value)
int getKey1() / setKey1(value)
int getOrder1() / setOrder1(value)
int getKey2() / setKey2(value)
int getOrder2() / setOrder2(value)
int getKey3() / setKey3(value)
int getOrder3() / setOrder3(value)
boolean getSortLeftToRight() / setSortLeftToRight(value)
boolean getCaseSensitive() / setCaseSensitive(value)
boolean getSortAsNumber() / setSortAsNumber(value)
clear()
addKey(key, order)
key: int
- The sorted column index(absolute position, column A is 0, B is 1, ...)order: int
- A addKey(key, order, customList)
key: int
- The sorted column index(absolute position, column A is 0, B is 1, ...)order: int
- A customList: String
- The custom sort list.addKey(key, type, order, customList)
key: int
- The sorted column index(absolute position, column A is 0, B is 1, ...)type: int
- A order: int
- A customList: Object
- The custom sort list.addKey(key, order, customList)
key: int
- The sorted column index(absolute position, column A is 0, B is 1, ...)order: int
- A customList: String[]
- The custom sort list.int[] sort(cells, startRow, startColumn, endRow, endColumn)
cells: Cells
- The cells contains the data area.startRow: int
- The start row of the area.startColumn: int
- The start column of the area.endRow: int
- The end row of the area.endColumn: int
- The end column of the area.int[] sort(cells, area)
cells: Cells
- The cells contains the data area.area: CellArea
- The area needed to sortint[] sort()