IRONSOFTWAREHOME
在 C# 中排序 Excel 范围
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Select a range
var range = workSheet["A1:D20"];

// Select a column(B)
var column = workSheet.GetColumn(1);

// Sort the range in ascending order (A to Z)
range.SortAscending();

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

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

workBook.SaveAs("sortExcelRange.xlsx");
Imports IronXL

Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Select a range
Dim range = workSheet("A1:D20")

' Select a column(B)
Dim column = workSheet.GetColumn(1)

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

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

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

workBook.SaveAs("sortExcelRange.xlsx")
NuGet Download
PM > Install-Package IronXL.Excel
在 C# 中排序 Excel 范围

在 C# 中排序 Excel 范围

在 Microsoft Excel 中,按字母顺序或数值顺序排列数据,使得人工分析数据成为可能。 IronXL使排序Excel Ranges在C#和VB.NET中变得极其简单。

在选定的范围或列上使用SortDescending方法,以适当的顺序应用排序。 不过,SortByColumn方法需要两个参数:第一个输入是要排序的列,第二个输入是排序顺序。

学习如何使用 C# 在 Excel 中使用命名区域
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,237,574版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户