Class DataSorter

DataSorter class

Summary description for DataSorter.

public class DataSorter

Properties

NameDescription
CaseSensitive { get; set; }Gets and sets whether case sensitive when comparing string.
HasHeaders { get; set; }Represents whether the range has headers.
Key1 { get; set; }Represents first sorted column index(absolute position, column A is 0, B is 1, …).
Key2 { get; set; }Represents second sorted column index(absolute position, column A is 0, B is 1, …).
Key3 { get; set; }Represents third sorted column index(absolute position, column A is 0, B is 1, …).
Keys { get; }Gets the key list of data sorter.
Order1 { get; set; }Represents sort order of the first key.
Order2 { get; set; }Represents sort order of the second key.
Order3 { get; set; }Represents sort order of the third key.
SortAsNumber { get; set; }Indicates whether sorting anything that looks like a number.
SortLeftToRight { get; set; }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.

Methods

NameDescription
AddKey(int, SortOrder)Adds sorted column index and sort order.
AddKey(int, SortOrder, string)Adds sorted column index and sort order with custom sort list.
AddKey(int, SortOrder, string[])Adds sorted column index and sort order with custom sort list.
AddKey(int, SortOnType, SortOrder, object)Adds sorted column index and sort order with custom sort list.
Clear()Clear all settings.
Sort()Sort the data in the range.
Sort(Cells, CellArea)Sort the data of the area.
Sort(Cells, int, int, int, int)Sorts the data of the area.

Examples


[C#]

//Instantiate a new Workbook object.
Workbook workbook = new Workbook("Book1.xls");
//Get the workbook datasorter object.
DataSorter sorter = workbook.DataSorter;
//Set the first order for datasorter object.
sorter.Order1 = Aspose.Cells.SortOrder.Descending;
//Define the first key.
sorter.Key1 = 0;
//Set the second order for datasorter object.
sorter.Order2 = Aspose.Cells.SortOrder.Ascending;
//Define the second key.
sorter.Key2 = 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.Worksheets[0].Cells, ca);
//Save the excel file.
workbook.Save("outBook.xls");

[Visual Basic]

'Instantiate a new Workbook object.
Dim workbook As Workbook = New Workbook("Book1.xls")
'Get the workbook datasorter object.
Dim sorter As DataSorter = workbook.DataSorter
'Set the first order for datasorter object
sorter.Order1 = Aspose.Cells.SortOrder.Descending
'Define the first key.
sorter.Key1 = 0
'Set the second order for datasorter object.
sorter.Order2 = Aspose.Cells.SortOrder.Ascending
'Define the second key.
sorter.Key2 = 1
'Create a cells area (range).
Dim ca As CellArea = 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 the 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