Class DataSorter
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Summary description for DataSorter.
public class DataSorter
Inheritance
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
//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");
'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")
Properties
CaseSensitive
Gets and sets whether case sensitive when comparing string.
public bool CaseSensitive { get; set; }
Property Value
HasHeaders
Represents whether the range has headers.
public bool HasHeaders { get; set; }
Property Value
Key1
Represents first sorted column index(absolute position, column A is 0, B is 1, …).
public int Key1 { get; set; }
Property Value
Key2
Represents second sorted column index(absolute position, column A is 0, B is 1, …).
public int Key2 { get; set; }
Property Value
Key3
Represents third sorted column index(absolute position, column A is 0, B is 1, …).
public int Key3 { get; set; }
Property Value
Keys
Gets the key list of data sorter.
public DataSorterKeyCollection Keys { get; }
Property Value
Order1
Represents sort order of the first key.
public SortOrder Order1 { get; set; }
Property Value
Order2
Represents sort order of the second key.
public SortOrder Order2 { get; set; }
Property Value
Order3
Represents sort order of the third key.
public SortOrder Order3 { get; set; }
Property Value
SortAsNumber
Indicates whether sorting anything that looks like a number.
public bool SortAsNumber { get; set; }
Property Value
SortLeftToRight
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.
public bool SortLeftToRight { get; set; }
Property Value
Methods
AddColorKey(int, SortOnType, SortOrder, Color)
Adds color sort key.
public void AddColorKey(int key, SortOnType type, SortOrder order, Color color)
Parameters
key
int
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
Color
The custom sort color.
AddKey(int, SortOrder)
Adds sorted column index and sort order.
public void AddKey(int key, SortOrder order)
Parameters
key
int
The sorted column index(absolute position, column A is 0, B is 1, …)
order
SortOrder
The sort order
AddKey(int, SortOrder, string)
Adds sorted column index and sort order with custom sort list.
public void AddKey(int key, SortOrder order, string customList)
Parameters
key
int
The sorted column index(absolute position, column A is 0, B is 1, …)
order
SortOrder
The sort order.
customList
string
The custom sort list.
AddKey(int, SortOnType, SortOrder, object)
Adds sorted column index and sort order with custom sort list.
public void AddKey(int key, SortOnType type, SortOrder order, object customList)
Parameters
key
int
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
object
The custom sort list.
Remarks
If type is SortOnType.CellColor or SortOnType.FontColor, the customList is Color.
AddKey(int, SortOrder, string[])
Adds sorted column index and sort order with custom sort list.
public void AddKey(int key, SortOrder order, string[] customList)
Parameters
key
int
The sorted column index(absolute position, column A is 0, B is 1, …)
order
SortOrder
The sort order.
customList
string[]
The custom sort list.
Clear()
Clear all settings.
public void Clear()
Sort(Cells, int, int, int, int)
Sorts the data of the area.
public int[] Sort(Cells cells, int startRow, int startColumn, int endRow, int endColumn)
Parameters
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.
Returns
int[]
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(Cells, CellArea)
Sort the data of the area.
public int[] Sort(Cells cells, CellArea area)
Parameters
cells
Cells
The cells contains the data area.
area
CellArea
The area needed to sort
Returns
int[]
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()
Sort the data in the range.
public int[] Sort()
Returns
int[]
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.