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");
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")
Top comments (0)