名前付き範囲の追加および参照
Contents
[
Hide
]
通常、列ラベルと行ラベルがセルをユニークに参照するために使用されます。ただし、セル、セルの範囲、数式、または定数値を表す記述的な名前を作成できます。Nameという単語は、セル、セルの範囲、数式、または定数値を表す文字列を指す場合があります。たとえば、Sales!C20:C30など、理解しにくい範囲を表すためにProductsなどの分かりやすい名前を使用します。ラベルは、同じワークシートのデータを参照する数式に使用できます。他のワークシートの範囲を表す場合は、名前を使用できます。Named rangesは、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(); |