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

可能的使用场景

Aspose.Cells提供了Range对象,该对象具有各种实用方法,方便用户轻松处理Excel范围。本文阐述了Range对象的以下方法或属性的用法。

  • 地址

获取范围的地址。

  • 单元格计数

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

  • 偏移

通过偏移获取范围。

  • 整列

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

  • 整行

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

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

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

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create empty workbook.
Workbook wb = new Workbook();
// Access first worksheet.
Worksheet ws = wb.Worksheets[0];
// Create range A1:B3.
Console.WriteLine("Creating Range A1:B3\n");
Range rng = ws.Cells.CreateRange("A1:B3");
// Print range address and cell count.
Console.WriteLine("Range Address: " + rng.Address);
Console.WriteLine("Range row Count: " + rng.RowCount);
Console.WriteLine("Range column Count: " + rng.ColumnCount);
// Formatting console output.
Console.WriteLine("----------------------");
Console.WriteLine("");
// Create range A1.
Console.WriteLine("Creating Range A1\n");
rng = ws.Cells.CreateRange("A1");
// Print range offset, entire column and entire row.
Console.WriteLine("Offset: " + rng.GetOffset(2, 2).Address);
Console.WriteLine("Entire Column: " + rng.EntireColumn.Address);
Console.WriteLine("Entire Row: " + rng.EntireRow.Address);
// Formatting console output.
Console.WriteLine("----------------------");
Console.WriteLine("");

控制台输出

 Creating Range A1:B3

Range Address: A1:B3

Cell Count: 6

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

Creating Range A1

Offset: C3

Entire Column: A:A

Entire Row: 1:1

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