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 欄、列和範圍變得簡單,只需少量程式碼。

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

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

準備好開始了嗎?

版本:2026.10剛剛發布

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 IronXL for Python
預訂您的免費 即時示範
Booking Badge

獲得數百萬工程師的信賴世界各地

Iron Software 的客戶標誌
獲取無需承諾的諮詢
您的資訊將永遠 保持機密。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
獲得數百萬工程師的信賴世界各地
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
Excel 用的 Python 模組下載
用 pip 安裝

版本: 2026.10

  1. 下載並安裝 Python 3.7+。
  2. 從 pypi.org 安裝 pip 如果尚未安裝。
  3. 在終端執行上述命令。
Python PDF 模組
下載 模組

版本: 2026.10

手動安裝到您的專案

  1. 下載套件
  2. 從終端執行此命令
    pip install IronXL-2026.10-py37-none-win_amd64.whi

授權從 $999