officefileapi-devexpress-dot-spreadsheet-dot-cellrange-e31863ec.md
Gets or sets the name of the cell range.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
string Name { get; set; }
Property Name As String
| Type | Description |
|---|---|
| String |
A string that specifies the name associated with the cell range.
|
To make is easier to refer to and use cell ranges (for example, in formulas), you can name them. To do this, set the Name property to the string, following the rules below:
After you specify the Name property value, the corresponding DefinedName object is created and added to the Worksheet.DefinedNames collection of the worksheet that contains the named range (CellRange.Worksheet). Thus, this worksheet is the scope of the created name. The DefinedName.RefersTo property is automatically set to the absolute reference of the cell range (including the worksheet name).
When you use the Name property to obtain a name associated with the current range, the name is first searched for in the Worksheet.DefinedNames collection. If the name is not found in the worksheet, the search continues in the workbook’s collection of defined names (IWorkbook.DefinedNames).
Refer to the Defined Names document for more information on defined names. For an example on the use of named ranges, see How to: Use Names in Formulas.
This example demonstrates how to create a named range of cells in a worksheet. You can do this in one of the following ways.
CellRange.Name property of the created CellRange object.Note
When specifying a name for a cell or range of cells, follow the rules listed in the Defined Names document.
using DevExpress.Spreadsheet;
// ...
IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets[0];
// Create a range.
CellRange rangeA2A4 = worksheet.Range["A2:A4"];
// Specify the name for the created range.
rangeA2A4.Name = "rangeA2A4";
// Create a new defined name with the specifed range name and absolute reference.
DefinedName definedName = worksheet.DefinedNames.Add("rangeC2D3", "Sheet1!$C$2:$D$3");
// Create a range using the specified defined name.
CellRange rangeC2D3 = worksheet.Range[definedName.Name];
Imports DevExpress.Spreadsheet
' ...
Dim workbook As IWorkbook = spreadsheetControl1.Document
Dim worksheet As Worksheet = workbook.Worksheets(0)
' Create a range.
Dim rangeA2A4 As CellRange = worksheet.Range("A2:A4")
' Specify the name for the created range.
rangeA2A4.Name = "rangeA2A4"
' Create a new defined name with the specifed range name and absolute reference.
Dim definedName As DefinedName = worksheet.DefinedNames.Add("rangeC2D3", "Sheet1!$C$2:$D$3")
' Create a range using the specified defined name.
Dim rangeC2D3 As CellRange = worksheet.Range(definedName.Name)
The following code snippets (auto-collected from DevExpress Examples) contain references to the Name property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
// Specify the created range name.
range.Name = "myRange";
// Specify the name for the created range.
range.Name = "myRange";
// Specify the name for the created range.
range.Name = "myRange";
' Specify the created range name.
range.Name = "myRange"
' Create a formula that sums up the values of all cells included in the specified range.
' Specify the name for the created range.
range.Name = "myRange"
' Specify the name for the created range.
range.Name = "myRange"
See Also