DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

1 1

Sort Excel Ranges in C#

IronXL makes sorting Excel Columns, Rows and Ranges extremely simple in C# and Vb.Net.

Arranging data in alphabetical or value order makes human analysis of data feasible in Microsoft Excel.

C#:

using IronXL;

WorkBook workbook = WorkBook.Load("test.xlsx");
WorkSheet worksheet = workbook.DefaultWorkSheet;

//Select a Range
Range range = worksheet["A1:D20"];

//This is how we can sort the current range in ascending order (A to Z)
range.SortAscending();


//This is how we can sort the current range in descending order (Z to A)
range.SortDescending();

workbook.SaveAs("SortExcelRange.xlsx");
Enter fullscreen mode Exit fullscreen mode

VB:

Imports IronXL

Private workbook As WorkBook = WorkBook.Load("test.xlsx")
Private worksheet As WorkSheet = workbook.DefaultWorkSheet

'Select a Range
Private range As Range = worksheet("A1:D20")

'This is how we can sort the current range in ascending order (A to Z)
range.SortAscending()


'This is how we can sort the current range in descending order (Z to A)
range.SortDescending()

workbook.SaveAs("SortExcelRange.xlsx")
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay