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 天试用密钥。
无需信用卡或创建账户
Python模块下载用于Excel
using 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 起