Search Results for

    Show / Hide Table of Contents

    ExcelFile.Sort Method

    Overloads

    • ExcelFile.Sort(TXlsCellRange, Boolean, Int32[], TSortOrder[], IComparer)
    • ExcelFile.Sort(TXlsCellRange, Boolean, Int32[], TSortOrder[], IComparer, TSortFormulaMode)

    ExcelFile.Sort(TXlsCellRange, Boolean, Int32[], TSortOrder[], IComparer)

    Sorts a range on the current sheet.

    Syntax

    Namespace: FlexCel.Core

    public void Sort(TXlsCellRange Range, Boolean ByRows, Int32[] Keys, TSortOrder[] SortOrder, IComparer Comparer)

    Parameters

    <-> Parameter Type Description
    Range TXlsCellRange Range to sort. It must not include headers.
    ByRows Boolean If true, rows will be sorted. If false, columns will.
    Keys Int32[] An array of integers indicating the columns or rows you want to use for sorting. Note that this number is absolute, for example column 1 always means column "A" no matter if the range we are sorting begins at column "B".
    A null array means sort by the first column or row, then by the second, etc. up to 8 entries.
    SortOrder TSortOrder[] An array of flags indicating whether to sort ascending or descending for each Key. If null, all sorts will be ascending. If not null and the array size is less than the size of the "Keys" parameter, all missing entries are assumed to be Ascending.
    Comparer IComparer Comparer to create a custom way to compare the different items. Set it to null to use default ordering.

    Examples

    To sort the range of cells from B7 to D100, on columns B Ascending and C Descending:

        xls.Sort(new TXlsCellRange("B7:D100"), //To sort the full sheet, you can pass null here.
            true, //Normally we want to sort the rows in the range. But we might want to sort columns and we can do it by setting this to false.
            new int[] { 2, 3 },// Sort by columns B and C (2 and 3)
            new TSortOrder[] { TSortOrder.Ascending, TSortOrder.Descending }, //Sort column B ascending, column C descending. If you want to sort everything in ascending order, just set this to null.
            null // Use the standard comparer.
            );
    

    See also

    • ExcelFile

    ExcelFile.Sort(TXlsCellRange, Boolean, Int32[], TSortOrder[], IComparer, TSortFormulaMode)

    Sorts a range on the current sheet.

    Syntax

    Namespace: FlexCel.Core

    public abstract void Sort(TXlsCellRange Range, Boolean ByRows, Int32[] Keys, TSortOrder[] SortOrder, IComparer Comparer, TSortFormulaMode SortFormulaMode)

    Parameters

    <-> Parameter Type Description
    Range TXlsCellRange Range to sort. It must not include headers.
    ByRows Boolean If true, rows will be sorted. If false, columns will.
    Keys Int32[] An array of integers indicating the columns or rows you want to use for sorting. Note that this number is absolute, for example column 1 always means column "A" no matter if the range we are sorting begins at column "B".
    A null array means sort by the first column or row, then by the second, etc. up to 8 entries.
    SortOrder TSortOrder[] An array of flags indicating whether to sort ascending or descending for each Key. If null, all sorts will be ascending. If not null and the array size is less than the size of the "Keys" parameter, all missing entries are assumed to be Ascending.
    Comparer IComparer Comparer to create a custom way to compare the different items. Set it to null to use default ordering.
    SortFormulaMode TSortFormulaMode Defines how formulas in the file will be changed when sorting.

    Examples

    To sort the range of cells from B7 to D100, on columns B Ascending and C Descending using TSortFormulaMode.ExcelLike:

        xls.Sort(new TXlsCellRange("B7:D100"), //To sort the full sheet, you can pass null here.
            true, //Normally we want to sort the rows in the range. But we might want to sort columns and we can do it by setting this to false.
            new int[] { 2, 3 },// Sort by columns B and C (2 and 3)
            new TSortOrder[] { TSortOrder.Ascending, TSortOrder.Descending }, //Sort column B ascending, column C descending. If you want to sort everything in ascending order, just set this to null.
            null, // Use the standard comparer.
            TSortFormulaMode.ExcelLike //Excel-like is faster, but won't change formulas outside the range being sorted.
            );
    

    See also

    • ExcelFile
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com