Back to Devexpress

DefinedName.Name Property

officefileapi-devexpress-dot-spreadsheet-dot-definedname.md

latest8.0 KB
Original Source

DefinedName.Name Property

Gets or sets the name of a cell, cell range, formula or constant.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string Name { get; set; }
vb
Property Name As String

Property Value

TypeDescription
String

A String value that specifies a name by which a cell, cell range, formula or constant can be referred.

|

Remarks

Use the Name property to give a cell, range of cells, formula or constant a name that explains its purpose and makes the use easier. For example, using the Sales name to refer to a cell range can be more understandable than using a cell reference, such as Sheet1!F1:F15. For more information, refer to the Defined Names document.

When setting the Name property value, take into account special syntax rules for names.

  • Start a name with a letter, the “_” underscore symbol or the “" backslash. The remaining characters in a name can be letters, numbers, periods and underscore symbols.

  • A name cannot be the same as a cell reference (for example, “A1”, “$M$15”, etc.).

  • A name cannot contain spaces (use underscore symbols and periods instead).

  • A name cannot be an empty string.

  • A name length cannot exceed 255 characters.

  • Uppercase and lowercase letters are interpreted identically. For example, you are not allowed to create the names Products and PRODUCTS in one scope.

When you name a cell or cell range via the CellRange.Name property, the corresponding DefinedName object is automatically added to the Worksheet.DefinedNames collection of a worksheet that contains this cell or range of cells. This object’s Name property is set to the specified value of the CellRange.Name property.

When you add a new defined name to a worksheet’s or workbook’s collection of defined names by calling the DefinedNameCollection.Add method, this method’s first parameter sets the Name property of the created DefinedName object.

Example

This example demonstrates how to create a named range of cells in a worksheet. You can do this in one of the following ways.

Note

When specifying a name for a cell or range of cells, follow the rules listed in the Defined Names document.

csharp
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];
vb
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 snippet (auto-collected from DevExpress Examples) contains a reference 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.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/CellActions.cs#L112

csharp
// Use the specified defined name to obtain the cell range.
CellRange B17D20 = worksheet.Range[definedName.Name];
#endregion #NamedRange

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/CellActions.vb#L104

vb
' Use the specified defined name to obtain the cell range.
            Dim B17D20 As CellRange = worksheet.Range(definedName.Name)
#End Region ' #NamedRange

See Also

RefersTo

Comment

How to: Create a Named Range of Cells

How to: Create Named Formulas

How to: Use Names in Formulas

DefinedName Interface

DefinedName Members

DevExpress.Spreadsheet Namespace