IRONSOFTWAREHOME
Sort Excel Ranges in C#
from ironxl import *

# Load the Excel workbook
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet

# Select a range
selected_range = worksheet["A1:D20"]

# Select a column(B)
column = worksheet.GetColumn(1)

# Sort the range in ascending order (A to Z)
selected_range.SortAscending()

# Sort the range by column(C) in ascending order
selected_range.SortByColumn("C", SortOrder.Ascending)

# Sort the column(B) in descending order (Z to A)
column.SortDescending()

# Save changes with the sorted range and column
workbook.SaveAs("sortExcelRange.xlsx")
pip install ironxl
Sort Excel Ranges in C#

Sort Excel Ranges in C#

Arranging data in alphabetical or numeric order makes analysis practical and efficient. IronXL for Python makes sorting Excel columns, rows, and ranges straightforward with a minimal amount of code.

Use the SortAscending or SortDescending methods on any selected range or column to apply sorting in the desired order. The SortByColumn method requires two parameters: the first is the column to sort by, and the second is the sort order.

Learn to Use Named Ranges in Excel with Python

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required