添加和引用命名范围
Contents
[
Hide
]
通常,列和行标签用于唯一引用单元格。但是您可以创建描述性名称来表示单元格、单元格区域、公式或常量值。这个单词姓名可以指表示单元格、单元格范围、公式或常量值的字符串。例如,使用易于理解的名称(例如 Products)来指代难以理解的范围(例如 Sales!C20:C30)。标签可用于引用同一工作表上数据的公式中;如果你想在另一个工作表上表示一个范围,你可以使用一个名称。命名范围是 Microsoft Excel 最强大的功能之一。用户可以为范围指定一个名称并在公式中使用该名称。 Aspose.Cells.GridWeb 支持此功能。
在公式中添加/引用命名范围
GridWeb 控件提供了两个类(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(); |