IRONSOFTWAREHOME
在 C# 中對 Excel 範圍進行排序
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
在 C# 中對 Excel 範圍進行排序

在 C# 中對 Excel 範圍進行排序

將資料按字母順序或數字順序排列,使分析實用且高效。 IronXL for Python 使排序 Excel 欄、列和範圍變得簡單,只需少量程式碼。

在任何選定的範圍或欄上使用 SortAscendingSortDescending 方法,以應用所需順序的排序。 SortByColumn 方法需要兩個參數:第一個是用來排序的欄,第二個是排序順序。

學習在 Excel 中使用 Python 命名範圍

準備好開始了嗎?

版本: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天試用金鑰
無需信用卡或帳戶建立