获取范围的地址、单元格计数、偏移、整列和整行

可能的使用场景

Aspose.Cells for Python via .NET提供了Range对象,该对象具有各种实用方法,可以方便用户轻松地处理Excel范围。本文说明了Range对象的以下方法或属性的用法。

  • 地址

获取范围的地址。

  • 单元格计数

获取范围中的所有单元格数。

  • 获取偏移

通过偏移获取范围。

  • 整列

获取代表包含指定范围的整列(或多列)的 Range 对象。

  • 整行

获取代表包含指定范围的整行(或多行)的 Range 对象。

获取范围的地址、单元格计数、偏移、整列和整行

下面的示例代码解释了上述方法和属性的用法。请参考以下给出的代码的控制台输出。

示例代码

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Create empty workbook.
wb = Workbook()
# Access first worksheet.
ws = wb.worksheets[0]
# Create range A1:B3.
print("Creating Range A1:B3\n")
rng = ws.cells.create_range("A1:B3")
# Print range address and cell count.
print("Range Address: " + rng.address)
print("Range row Count: " + str(rng.row_count))
print("Range column Count: " + str(rng.column_count))
# Formatting console output.
print("----------------------")
print("")
# Create range A1.
print("Creating Range A1\n")
rng = ws.cells.create_range("A1")
# Print range offset, entire column and entire row.
print("Offset: " + rng.get_offset(2, 2).address)
print("Entire Column: " + rng.entire_column.address)
print("Entire Row: " + rng.entire_row.address)
# Formatting console output.
print("----------------------")
print("")

控制台输出

 Creating Range A1:B3

Range Address: A1:B3

Cell Count: 6

\----------------------

Creating Range A1

Offset: C3

Entire Column: A:A

Entire Row: 1:1

\----------------------