public class DataSorter
extends java.lang.Object
Example
//Instantiate a new Workbook object.
Workbook workbook = new Workbook("Book1.xls");
//Get the workbook datasorter object.
DataSorter sorter = workbook.getDataSorter();
//Set the first order for datasorter object.
sorter.setOrder1(com.aspose.cells.SortOrder.DESCENDING);
//Define the first key.
sorter.setKey1(0);
//Set the second order for datasorter object.
sorter.setOrder2(com.aspose.cells.SortOrder.ASCENDING);
//Define the second key.
sorter.setKey2(1);
//Create a cells area (range).
CellArea ca = new 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("outBook.xls");
| Modifier and Type | Method and Description |
|---|---|
void |
addColorKey(int key,
int type,
int order,
Color color)
Adds color sort key.
|
void |
addKey(int key,
int order)
Adds sorted column index and sort order.
|
void |
addKey(int key,
int type,
int order,
java.lang.Object customList)
Adds sorted column index and sort order with custom sort list.
|
void |
addKey(int key,
int order,
java.lang.String customList)
Adds sorted column index and sort order with custom sort list.
|
void |
addKey(int key,
int order,
java.lang.String[] customList)
Adds sorted column index and sort order with custom sort list.
|
void |
clear()
Clear all settings.
|
boolean |
getCaseSensitive()
Gets whether case sensitive when comparing string.
|
int |
getKey1()
Represents first sorted column index(absolute position, column A is 0, B is 1, ...).
|
int |
getKey2()
Represents second sorted column index(absolute position, column A is 0, B is 1, ...).
|
int |
getKey3()
Represents third sorted column index(absolute position, column A is 0, B is 1, ...).
|
DataSorterKeyCollection |
getKeys()
Gets the key list of data sorter.
|
int |
getOrder1()
Represents sort order of the first key.
|
int |
getOrder2()
Represents sort order of the second key.
|
int |
getOrder3()
Represents sort order of the third key.
|
boolean |
getSortAsNumber()
Indicates whether sorting anything that looks like a number.
|
boolean |
getSortLeftToRight()
True means that sorting orientation is from left to right.
|
boolean |
hasHeaders()
Represents whether the range has headers.
|
void |
setCaseSensitive(boolean value)
Sets whether case sensitive when comparing string.
|
void |
setHasHeaders(boolean value)
Represents whether the range has headers.
|
void |
setKey1(int value)
Represents first sorted column index(absolute position, column A is 0, B is 1, ...).
|
void |
setKey2(int value)
Represents second sorted column index(absolute position, column A is 0, B is 1, ...).
|
void |
setKey3(int value)
Represents third sorted column index(absolute position, column A is 0, B is 1, ...).
|
void |
setOrder1(int value)
Represents sort order of the first key.
|
void |
setOrder2(int value)
Represents sort order of the second key.
|
void |
setOrder3(int value)
Represents sort order of the third key.
|
void |
setSortAsNumber(boolean value)
Indicates whether sorting anything that looks like a number.
|
void |
setSortLeftToRight(boolean value)
True means that sorting orientation is from left to right.
|
int[] |
sort()
Sort the data in the range.
|
int[] |
sort(Cells cells,
CellArea area)
Sort the data of the area.
|
int[] |
sort(Cells cells,
int startRow,
int startColumn,
int endRow,
int endColumn)
Sorts the data of the area.
|
public DataSorterKeyCollection getKeys()
public void clear()
public boolean hasHeaders()
public void setHasHeaders(boolean value)
public void addKey(int key,
int order)
key - The sorted column index(absolute position, column A is 0, B is 1, ...)order - SortOrder. The sort orderpublic void addKey(int key,
int order,
java.lang.String customList)
key - The sorted column index(absolute position, column A is 0, B is 1, ...)order - SortOrder. The sort order.customList - The custom sort list.public void addColorKey(int key,
int type,
int order,
Color color)
key - The sorted column index(absolute position, column A is 0, B is 1, ...)type - SortOnType. The sorted color value type.order - SortOrder. The sort order.color - The custom sort color.public void addKey(int key,
int type,
int order,
java.lang.Object customList)
Remarks
If type is SortOnType.CellColor or SortOnType.FontColor, the customList is Color.key - The sorted column index(absolute position, column A is 0, B is 1, ...)type - SortOnType. The sorted value type.order - SortOrder. The sort order.customList - The custom sort list.public void addKey(int key,
int order,
java.lang.String[] customList)
key - The sorted column index(absolute position, column A is 0, B is 1, ...)order - SortOrder. The sort order.customList - The custom sort list.public int getKey1()
public void setKey1(int value)
public int getOrder1()
See SortOrder.
public void setOrder1(int value)
See SortOrder.
public int getKey2()
public void setKey2(int value)
public int getOrder2()
See SortOrder.
public void setOrder2(int value)
See SortOrder.
public int getKey3()
public void setKey3(int value)
public int getOrder3()
See SortOrder.
public void setOrder3(int value)
See SortOrder.
public boolean getSortLeftToRight()
public void setSortLeftToRight(boolean value)
public boolean getCaseSensitive()
public void setCaseSensitive(boolean value)
public boolean getSortAsNumber()
public void setSortAsNumber(boolean value)
public int[] sort(Cells cells, int startRow, int startColumn, int endRow, int endColumn)
cells - The cells contains the data area.startRow - The start row of the area.startColumn - The start column of the area.endRow - The end row of the area.endColumn - The end column of the area.public int[] sort(Cells cells, CellArea area)
cells - The cells contains the data area.area - The area needed to sortpublic int[] sort()
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2003-2025. All Rights Reserved.