名前付き範囲の使用
Contents
[
Hide
]
通常、ワークシートの列と行のラベルを使用して、それらの列と行内のセルを参照します。ただし、セル、セルの範囲、数式、または定数値を表すわかりやすい名前を作成できます。言葉名前セル、セル範囲、数式、または定数値を表す文字列を参照できます。たとえば、Sales!C20:C30 のように、セル、セルの範囲、数式、または定数値を表すために、Products などのわかりやすい名前を使用して、理解しにくい範囲を参照します。ラベルは、同じワークシートのデータを参照する数式で使用できます。別のワークシートで範囲を表したい場合は、名前を使用できます。名前付き範囲は、Microsoft の最も強力な機能の 1 つです。ユーザーは名前付き範囲に名前を割り当てて、このセル範囲を数式でその名前で参照できるようにすることができます。Aspose.Cells.GridDesktopはこの機能をサポートしています。
数式での名前付き範囲の追加/参照
GridDesktop コントロールは、Excel ファイル内の名前付き範囲のインポート/エクスポートをサポートしており、2 つのクラス (名前とNameCollection) 名前付き範囲を操作します。
次のコード スニペットは、それらの使用方法に役立ちます。
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 | |
// Clear the Worsheets first | |
_grid.Clear(); | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specifying the path of Excel file using ImportExcelFile method of the control | |
_grid.ImportExcelFile(dataDir + "book1.xlsx"); | |
// Apply a formula to a cell that refers to a named range "Rang1" | |
_grid.Worksheets[0].Cells["G6"].SetCellValue("=SUM(Range1)"); | |
// Add a new named range "MyRange" with based area A2:B5 | |
int index = _grid.Names.Add("MyRange", "Sheet1!A2:B5"); | |
// Apply a formula to G7 cell | |
_grid.Worksheets[0].Cells["G7"].SetCellValue("=SUM(MyRange)"); | |
// Calculate the results of the formulas | |
_grid.RunAllFormulas(); | |
// Save the Excel file | |
_grid.ExportExcelFile(dataDir + @"ouputBook1_out.xlsx"); |