Log In
[Expand]Welcome to DevExpress .NET Documentation
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Document Server
  Product Information
 [Expand]Redistribution and Deployment
 [Collapse]Spreadsheet Document Server
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Spreadsheet Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Mail Merge
   [Expand]Rows and Columns
   [Expand]Import and Export Data
   [Expand]Data Binding
   [Expand]Mail Merge
   [Expand]Formatting Cells
   [Expand]Conditional Formatting
   [Expand]Pivot Tables
 [Expand]XL Export Library
 [Expand]Rich Edit Document Server
 [Expand]Snap Document Server
 [Expand]PDF Document Processor
 [Expand]Compression Library
 [Expand]Bar Code Library
 [Expand]Unit Conversion Library
 [Expand]API Reference
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation


To sort data in a range in ascending or descending order, use the Worksheet.Sort method. Note that this method has several overloads with serious advantages. You can specify the column by which to sort a multi-column range, sort by multiple columns, or use a custom comparer.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T217615.

To sort data by multiple columns, follow the steps below.

  1. Create the SortField object for each of the columns from which to sort. Specify the position of this column within the range using the SortField.ColumnOffset property and assign a comparer using the SortField.Comparer property. Instead of implementing your own comparer with the System.Collections.Generic.IComparer`1[[DevExpress.Spreadsheet.CellValue]] interface, you can use one of the built-in comparers which are responsible for sort operations performed by end-users. There are two built-in comparers - Worksheet.Comparers.Ascending is used for sorting in ascending order; Worksheet.Comparers.Descending is used for sorting in descending order.

  2. Create a list containing sort fields.

  3. Call the Worksheet.Sort method with two parameters: the first is the Range to be sorted, the other is the list of sort fields.

The image below shows the result (the workbook is opened in Microsoft® Excel®). The cell range is sorted by the first and second columns in ascending order.

Is this topic helpful?​​​​​​​