Interface IName
Represents a defined name for a range of cells. Names can be either built-in names such as Database, Print_Area, and Auto_Open or custom names.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.NET.dll
Syntax
public interface IName : IParentApplication
Remarks
Below these rules are should be followed, when you're creating a named range in Excel.
- The first character of a name must be one of the following characters: letter, underscore (_), backslash ().
- Remaining characters in the name can be letters, numbers, periods, underscore characters.
- The following are not allowed: Space characters are not allowed as part of a name. Names can't look like cell addresses, such as A$35 or R2D2. C, c, R, r - can't be used as names. Excel uses them as selection shortcuts.
- Names are not case sensitive. For example, North and NORTH are treated as the same name. To know more about Named Ranges refer this link.
Properties
Description
Gets/sets the comment associated with the named range.
Declaration
string Description { get; set; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Description property for named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("NamedTitle");
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Sets the comment associated with the named range
namedTitle.Description = "Sample Workbook Description";
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("NamedData");
namedData.RefersToRange = sheet.Range["A2:C3"];
//sets the comment associated with the named range
namedData.Description = "Sample Worksheet Description";
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Index
Returns the index number of the object within the collection of similar objects.
Declaration
int Index { get; }
Property Value
Type |
---|
System.Int32 |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Index property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("NamedTitle");
//Returns the index number of the object within the collection of similar objects
workbook.Names[0].Name = "Titles";
workbook.Names[0].Value = "Sheet1!$A$1:$C$1";
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("NamedData");
//Returns the index number of the object within the collection of similar objects
sheet.Names[0].Name = "Records";
sheet.Names[0].Value = "Sheet1!$A$2:$C$3";
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
IsLocal
Indicates whether name is local.
Declaration
bool IsLocal { get; }
Property Value
Type |
---|
System.Boolean |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of IsLocal property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Indicates whether name is local
bool isLocal = namedData.IsLocal;
if (isLocal)
{
//Your Code Here
}
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Name
Returns or sets the name of the object. Read / write String.
Declaration
string Name { get; set; }
Property Value
Type |
---|
System.String |
Remarks
Below these rules are should be followed, when you're creating a named range in Excel.
- The first character of a name must be one of the following characters: letter, underscore (_), backslash ().
- Remaining characters in the name can be letters, numbers, periods, underscore characters.
- The following are not allowed: Space characters are not allowed as part of a name. Names can't look like cell addresses, such as A$35 or R2D2. C, c, R, r - can't be used as names. Excel uses them as selection shortcuts.
- Names are not case sensitive. For example, North and NORTH are treated as the same name. To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Name property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("NamedTitle");
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Sets the name of the object
namedTitle.Name = "Titles";
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("NamedData");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Sets the name of the object
namedData.Name = "Records";
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
NameLocal
Returns or sets the name of the object, in the language of the user. Read / write String for Name.
Declaration
string NameLocal { get; set; }
Property Value
Type |
---|
System.String |
Remarks
Below these rules are should be followed, when you're creating a named range in Excel.
- The first character of a name must be one of the following characters: letter, underscore (_), backslash ().
- Remaining characters in the name can be letters, numbers, periods, underscore characters.
- The following are not allowed: Space characters are not allowed as part of a name. Names can't look like cell addresses, such as A$35 or R2D2. C, c, R, r - can't be used as names. Excel uses them as selection shortcuts.
- Names are not case sensitive. For example, North and NORTH are treated as the same name. To know more about Named Ranges refer this link.
Examples
The following code illustrates use of NameLocal property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("NamedTitle");
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Sets the name of the object
namedTitle.NameLocal = "TitlesLocal";
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("NamedData");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Sets the name of the object
namedData.NameLocal = "RecordsLocal";
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
RefersTo
Gets named range RefersTo. Read-only.
Declaration
string RefersTo { get; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of RefersTo property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Gets named range RefersTo
string refersTo = namedData.RefersTo;
if (refersTo != string.Empty)
{
//Your Code Here
}
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
RefersToR1C1
Gets named range RefersTo in R1C1 style. Read-only.
Declaration
string RefersToR1C1 { get; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of RefersToR1C1 property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Gets named range RefersTo in R1C1 style
string refersToR1C1 = namedData.RefersToR1C1;
if (refersToR1C1 != string.Empty)
{
//Your Code Here
}
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
RefersToRange
Gets / sets IRange associated with the Name object.
Declaration
IRange RefersToRange { get; set; }
Property Value
Type |
---|
IRange |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of RefersToRange property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("Titles");
//Sets Range associated with the Name object
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
//Sets Range associated with the Name object
namedData.RefersToRange = sheet.Range["A2:C3"];
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Scope
Returns string representation of the name's scope. Read-only. The Scope property have a separate scope values for Workbook and Worksheet.
Declaration
string Scope { get; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Scope property for named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("NamedTitle");
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Gets string representation of the name's scope for workbook
string scopeTitle = namedTitle.Scope;
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("NamedData");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Gets string representation of the name's scope for worksheet
string scopeData = namedData.Scope;
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Value
For the Name object, a string containing the formula that the name is defined to refer to. The string is in A1-style notation in the language of the macro, without an equal sign.
Declaration
string Value { get; set; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Value property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("Titles");
//Sets string containing the formula that the name is defined to RefersToRange
namedTitle.Value = "Sheet1!$A$1:$C$1";
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
//Sets string containing the formula that the name is defined to RefersToRange
namedData.Value = "Sheet1!$A$2:$C$3";
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
ValueR1C1
Gets named range Value in R1C1 style. Read-only.
Declaration
string ValueR1C1 { get; }
Property Value
Type |
---|
System.String |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of ValueR1C1 property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Gets named range Value in R1C1 style
string valueR1C1 = namedData.ValueR1C1;
if (valueR1C1 != string.Empty)
{
//Your Code Here
}
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Visible
Determines whether the object is visible. Read / write Boolean.
Declaration
bool Visible { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Visible property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Student ID";
sheet.Range["B1"].Text = "Student Name";
sheet.Range["C1"].Text = "Mark(Out of 100)";
sheet.Range["A1:C1"].AutofitColumns();
sheet.Range["A2"].Number = 1;
sheet.Range["A3"].Number = 2;
sheet.Range["B2"].Text = "Andrew";
sheet.Range["B3"].Text = "Marson";
sheet.Range["C2"].Number = 77;
sheet.Range["C3"].Number = 88;
//Create a Named Range using workbook
IName namedTitle = workbook.Names.Add("Titles");
namedTitle.RefersToRange = sheet.Range["A1:C1"];
//Create a Named Range using worksheet
IName namedData = sheet.Names.Add("Records");
namedData.RefersToRange = sheet.Range["A2:C3"];
//Set name visibility as false.
namedData.Visible = false;
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Worksheet
Returns parent IWorksheet. Read-only.
Declaration
IWorksheet Worksheet { get; }
Property Value
Type |
---|
IWorksheet |
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates use of Worksheet property in named range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Gets parent worksheet of named range
IWorksheet namedWorksheet = sheet.Names[0].Worksheet;
if(namedWorksheet != null)
{
//Your Code Here
}
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}
Methods
Delete()
Deletes the Named Range object.
Declaration
void Delete()
Remarks
To know more about Named Ranges refer this link.
Examples
The following code illustrates how to delete a named range in wokbook and worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Deletes the named range object using workbook
workbook.Names[0].Delete();
//Deletes the named range object using worksheet
sheet.Names[0].Delete();
workbook.SaveAs("NamedRange.xlsx");
workbook.Close();
}