名前付き範囲の追加と参照
Contents
[
Hide
]
通常、列と行のラベルは、セルを一意に参照するために使用されます。ただし、セル、セルの範囲、数式、または定数値を表すわかりやすい名前を作成できます。言葉名前セル、セル範囲、数式、または定数値を表す文字列を参照できます。たとえば、Products などのわかりやすい名前を使用して、Sales!C20:C30 などのわかりにくい範囲を参照します。ラベルは、同じワークシートのデータを参照する数式で使用できます。別のワークシートで範囲を表したい場合は、名前を使用できます。名前付き範囲 Microsoft Excel の最も強力な機能の 1 つです。ユーザーは範囲に名前を割り当て、その名前を数式で使用できます。 Aspose.Cells.GridWeb はこの機能をサポートしています。
数式での名前付き範囲の追加/参照
GridWeb コントロールには、名前付き範囲を操作するための 2 つのクラス (GridName と GridNameCollection) が用意されています。次のコード スニペットは、名前付き範囲を作成し、数式でアクセスする方法を理解するのに役立ちます。
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-.NET | |
// Inserting dummy data | |
GridWeb1.WorkSheets[0].Cells["B1"].PutValue(100); | |
GridWeb1.WorkSheets[0].Cells["B2"].PutValue(200); | |
GridWeb1.WorkSheets[0].Cells["B3"].PutValue(300); | |
GridWeb1.WorkSheets[0].Cells["B4"].PutValue(400); | |
// Add a new named range "MyRange" with based area B1:B4 | |
GridWeb1.WorkSheets.Names.Add("MyRange", "Sheet1!B1:B4"); | |
// Apply a formula to a cell that refers to a named range "MyRange" | |
GridWeb1.WorkSheets[0].Cells["A1"].Formula = "=SUM(MyRange)"; | |
// Apply a formula to A2 cell | |
GridWeb1.WorkSheets[0].Cells["A2"].Formula = "=Average(MyRange)"; | |
// Calculate the results of the formulas | |
GridWeb1.WorkSheets.CalculateFormula(); |