Click or drag to resize
NamedRangeCollection Class
Collection of the descriptive names which are used to represent cells, ranges of cells, formulas, or constant values.
Inheritance Hierarchy
SystemObject
  GemBox.SpreadsheetNamedRangeCollection

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 41.3.30.1032
Syntax
public sealed class NamedRangeCollection : IEnumerable<NamedRange>, 
	IEnumerable

The NamedRangeCollection type exposes the following members.

Properties
Methods
  NameDescription
Public methodCode exampleAdd(String, CellRange)
Adds a new named range. Named ranges are used to represent cells, ranges of cells, formulas or constant values.
Public methodCode exampleAdd(String, CellRange, Boolean)
Adds a new named range. Named ranges are used to represent cells, ranges of cells, formulas or constant values.
Public methodGetEnumerator
Returns an enumerator that can iterate through a collection.
Public methodSetPrintArea(CellRange)
Sets print area.
Public methodSetPrintArea(CellRange)
Sets multi-range print area.
Public methodSetPrintArea(IEnumerableCellRange)
Sets multi-range print area.
Public methodSetPrintTitles(ExcelColumn, Int32)
Sets print titles (columns to repeat at left).
Public methodSetPrintTitles(ExcelRow, Int32)
Sets print titles (rows to repeat at top).
Public methodSetPrintTitles(ExcelColumnRowBase, Int32, ExcelColumnRowBase, Int32)
Sets print titles.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodIEnumerableGetEnumerator
Returns an enumerator that can iterate through a collection.
Top
Remarks
You can use the labels of columns and rows on a worksheet to refer to the cells within those columns and rows. Or you can create descriptive names to represent cells, ranges of cells, formulas, or constant values. Labels can be used in formulas that refer to data on the same worksheet; if you want to represent a range on another worksheet, use a name. You can also create 3-D names that represent the same cell or range of cells across multiple worksheets.
Examples

Following code demonstrates how to use formulas and named ranges. It shows next features: cell references (both absolute and relative), unary and binary operators, constant operands (integer and floating point), functions and named cell ranges. At the end, code shows how to calculate worksheet formulas.

ws.Cells["A1"].Value = 5;
ws.Cells["A2"].Value = 6;
ws.Cells["A3"].Value = 10;

ws.Cells["C1"].Formula = "=A1+A2";
ws.Cells["C2"].Formula = "=$A$1-A3";
ws.Cells["C3"].Formula = "=COUNT(A1:A3)";
ws.Cells["C4"].Formula = "=AVERAGE($A$1:$A$3)";
ws.Cells["C5"].Formula = "=SUM(A1:A3,2,3)";
ws.Cells["C7"].Formula = "= 123 - (-(-(23.5)))";

ws.NamedRanges.Add("DataRange", ws.Cells.GetSubrange("A1", "A3"));
ws.Cells["C8"].Formula = "=MAX(DataRange)";

CellRange cr = ws.Cells.GetSubrange("B9", "C10");
cr.Merged = true;
cr.Formula = "=A1*25";

ws.Calculate();
See Also