Workbook.DefinedNames Property
Gets the collection of defined names whose scope is the current workbook.
Use of this property in production code requires a license to the DevExpress Document Server or the DevExpress Universal Subscription.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v17.2.dll
Declaration
Property Value
Type | Description |
---|---|
DefinedNameCollection | A DefinedNameCollection collection of a worksheet’s defined names. |
Remarks
Each defined name has a scope - an area (an individual worksheet or entire workbook) within which a name is recognized and can be used without qualification. So, each worksheet contained in the workbook and the entire workbook has it’s own collection of defined names that can be accessed by the Worksheet.DefinedNames or DefinedNames property, respectively.
Use members of the DefinedNameCollection object to create new defined names for cells and formulas, access an individual defined name by its index in the collection or name, remove names from the collection, etc.
For more details on defined names, refer to the Defined Names document.
Example
This example demonstrates how to define names for formulas. To do this, call the DefinedNameCollection.Add method with a name to be associated with a formula and the formula string passed as parameters. Use the Worksheet.DefinedNames or Workbook.DefinedNames property to access and modify the collection of defined names of a particular worksheet or entire workbook, depending on which scope you want to specify for a name.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-e4339
Worksheet worksheet1 = workbook.Worksheets["Sheet1"];
Worksheet worksheet2 = workbook.Worksheets["Sheet2"];
// Create a name for a formula that sums up the values of all cells included in the "A1:C3" range of the "Sheet1" worksheet.
// The scope of this name will be limited by the "Sheet1" worksheet.
worksheet1.DefinedNames.Add("Range_Sum", "=SUM(Sheet1!$A$1:$C$3)");
// Create a name for a formula that doubles the value resulting from the "Range_Sum" named formula and
// make this name available within the entire workbook.
workbook.DefinedNames.Add("Range_DoubleSum", "=2*Sheet1!Range_Sum");
// Create formulas that use other formulas with the specified names.
worksheet2.Cells["C2"].Formula = "=Sheet1!Range_Sum";
worksheet2.Cells["C3"].Formula = "=Range_DoubleSum";
worksheet2.Cells["C4"].Formula = "=Range_DoubleSum + 100";
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DefinedNames 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.