获取范围的地址、单元格计数、偏移、整列和整行
Contents
[
Hide
]
可能的使用场景
Aspose.Cells 提供了 Range 对象,该对象具有各种实用方法,可帮助用户轻松处理 Excel 范围。本文阐明了 Range 对象的以下方法或属性的用法。
- 地址
获取范围的地址。
- 单元格计数
获取范围中的所有单元格数。
- 偏移
通过偏移获取范围。
- 整列
获取代表包含指定范围的整列(或多列)的 Range 对象。
- 整行
获取代表包含指定范围的整行(或多行)的 Range 对象。
获取范围的地址、单元格计数、偏移、整列和整行
下面的示例代码解释了上述方法和属性的用法。请参考以下给出的代码的控制台输出。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Create empty workbook. | |
Workbook wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Create range A1:B3. | |
System.out.println("Creating Range A1:B3\n"); | |
Range rng = ws.getCells().createRange("A1:B3"); | |
// Print range address and cell count. | |
System.out.println("Range Address: " + rng.getAddress()); | |
System.out.println("Cell Count: " + rng.getCellCount()); | |
// Formatting console output. | |
System.out.println("----------------------"); | |
System.out.println(""); | |
// Create range A1. | |
System.out.println("Creating Range A1\n"); | |
rng = ws.getCells().createRange("A1"); | |
// Print range offset, entire column and entire row. | |
System.out.println("Offset: " + rng.getOffset(2, 2).getAddress()); | |
System.out.println("Entire Column: " + rng.getEntireColumn().getAddress()); | |
System.out.println("Entire Row: " + rng.getEntireRow().getAddress()); | |
// Formatting console output. | |
System.out.println("----------------------"); | |
System.out.println(""); |
控制台输出
Creating Range A1:B3
Range Address: A1:B3
Cell Count: 6
\----------------------
Creating Range A1
Offset: C3
Entire Column: A:A
Entire Row: 1:1
\----------------------