ワークブック(グローバル)とワークシート限定の名前付き範囲の作成
Contents
[
Hide
]
Microsoft Excelでは、ワークブック(またはグローバルスコープとしても知られています)とワークシートの2つの異なるスコープで名前付き範囲を定義できます。
- ワークブックスコープの名前付き範囲は、そのワークブック内の任意のワークシートから、名前を単純に使用することでアクセスできます。
- ワークシートスコープの名前付き範囲は、それが作成された特定のワークシートの参照でアクセスされます。
Aspose.Cellsは、ワークブックスコープとワークシートスコープの名前付き範囲の追加に関して、Microsoft Excelと同じ機能を提供します。ワークシートスコープの名前付き範囲を作成する場合、名前付き範囲にワークシートの参照を使用して、それをワークシートスコープの名前付き範囲として指定する必要があります。
以下のコードサンプルは、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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddNamedRangeWithWorkbookScope.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Get Worksheets collection | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Accessing the first worksheet in the Excel file | |
Worksheet sheet = worksheets.get(0); | |
// Get worksheet Cells collection | |
Cells cells = sheet.getCells(); | |
// Creating a workbook scope named range | |
Range namedRange = cells.createRange("A1", "C10"); | |
namedRange.setName("workbookScope"); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
ワークシートスコープを持つ名前付き範囲を追加する
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddNamedRangeWithWorkbookScope.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Get Worksheets collection | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Accessing the first worksheet in the Excel file | |
Worksheet sheet = worksheets.get(0); | |
// Get worksheet Cells collection | |
Cells cells = sheet.getCells(); | |
// Creating a workbook scope named range | |
Range namedRange = cells.createRange("A1", "C10"); | |
namedRange.setName("Sheet1!local"); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |