用 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 方法需要兩個參數:第一個是用來排序的欄,第二個是排序順序。