在 C# 中排序 Excel 范围
按字母顺序或数字顺序排列数据可以使分析变得实用且高效。 IronXL for Python使排序Excel列、行和范围变得简单,只需少量代码。
对任何选定的范围或列使用SortAscending或SortDescending方法,以所需顺序应用排序。 SortByColumn方法需要两个参数:第一个是要排序的列,第二个是排序顺序。
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")按字母顺序或数字顺序排列数据可以使分析变得实用且高效。 IronXL for Python使排序Excel列、行和范围变得简单,只需少量代码。
对任何选定的范围或列使用SortAscending或SortDescending方法,以所需顺序应用排序。 SortByColumn方法需要两个参数:第一个是要排序的列,第二个是排序顺序。