//Instantiate a new Workbook object.
Workbook workbook = new Workbook("C:\\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("C:\\outBook.xls");
public int[] sort(Cells cells, int startRow, int startColumn, int endRow, int endColumn)
Sorts the data of the area.
Parameters:
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.
Returns:
the original indices(absolute position, for example, column A is 0, B is 1, ...) of the sorted rows/columns.
If no rows/columns needs to be moved by this sorting operation, null will be returned.
the original indices(absolute position, for example, column A is 0, B is 1, ...) of the sorted rows/columns.
If no rows/columns needs to be moved by this sorting operation, null will be returned.
sort
public int[] sort()
Sort the data in the range.
Returns:
the original indices(absolute position, for example, column A is 0, B is 1, ...) of the sorted rows/columns.
If no rows/columns needs to be moved by this sorting operation, null will be returned.