範囲のアドレス、セル数、オフセット、全列、および全行を取得する
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsは、Excelの範囲を容易に扱うための様々なユーティリティメソッドを持つRangeオブジェクトを提供します。この記事では、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
\----------------------