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
AddColorKey(int, SortOnType, SortOrder, Color)Adds color sort key.
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

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using System;

    public class DataSorterDemo
    {
        public static void DataSorterExample()
        {
            // Instantiate a new Workbook object
            Workbook workbook = new Workbook("DataSorter_original.xlsx");

            // Get the workbook DataSorter object
            DataSorter sorter = workbook.DataSorter;

            // 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)
            CellArea ca = new CellArea
            {
                StartRow = 0,
                StartColumn = 0,
                EndRow = 13,
                EndColumn = 1
            };

            // Sort data in the specified data range (A1:B14)
            sorter.Sort(workbook.Worksheets[0].Cells, ca);

            // Save the excel file
            workbook.Save("DataSorterExample.xlsx");
            workbook.Save("DataSorterExample.pdf");
        }
    }
}

See Also