DataSorter class

DataSorter class

Summary description for DataSorter.

The DataSorter type exposes the following members:

Properties

PropertyDescription
keysGets the key list of data sorter.
has_headersRepresents whether the range has headers.
key1Represents first sorted column index(absolute position, column A is 0, B is 1, …).
order1Represents sort order of the first key.
key2Represents second sorted column index(absolute position, column A is 0, B is 1, …).
order2Represents sort order of the second key.
key3Represents third sorted column index(absolute position, column A is 0, B is 1, …).
order3Represents sort order of the third key.
sort_left_to_rightTrue means that sorting orientation is from left to right.
False means that sorting orientation is from top to bottom.
The default value is false.
case_sensitiveGets and sets whether case sensitive when comparing string.
sort_as_numberIndicates whether sorting anything that looks like a number.

Methods

MethodDescription
add_keyAdds sorted column index and sort order.
add_keyAdds sorted column index and sort order with custom sort list.
add_keyAdds sorted column index and sort order with custom sort list.
add_keyAdds sorted column index and sort order with custom sort list.
sortSorts the data of the area.
sortSort the data of the area.
sortSort the data in the range.
clearClear all settings.

Example

from aspose.cells import CellArea, SortOrder, Workbook

# Instantiate a new Workbook object.
workbook = Workbook("Book1.xls")
# Get the workbook datasorter object.
sorter = workbook.data_sorter
# Set the first order for datasorter object.
sorter.order1 = SortOrder.DESCENDING
# Define the first key.
sorter.key1 = 0
# Set the second order for datasorter object.
sorter.order2 = SortOrder.ASCENDING
# Define the second key.
sorter.key2 = 1
# Create a cells area (range).
ca = CellArea()
# Specify the start row index.
ca.start_row = 0
# Specify the start column index.
ca.start_column = 0
# Specify the last row index.
ca.end_row = 13
# Specify the last column index.
ca.end_column = 1
# Sort data in the specified data range (A1:B14)
sorter.sort(workbook.worksheets[0].cells, ca)
# Save the excel file.
workbook.save("outBook.xls")

See Also