This topic describes the API operations related to Names in spreadsheet documents.
Name
ActiveWorkbook.ActiveSheet.Names.Item(Index)
Obtains a single Name object in the active worksheet.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index)expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Obtain a single Name object. const name = await names.Item(1); }
Methods
ActiveWorkbook.ActiveSheet.Names.Item(Index).Delete()
Deletes a single name in the active worksheet by using the Delete() method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index).Delete()expression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Obtain a single Name object. const name = await names.Item(1); //Delete the name. await name.Delete(); }
Properties
ActiveWorkbook.ActiveSheet.Names.Item(Index).Name
Obtains the specific name of a single Name object by using the Name property.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index).Nameexpression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Obtain a single Name object. const name = await names.Item(1); //Obtain the specific name. const nameName = await name.Name; console.log(nameName); }
ActiveWorkbook.ActiveSheet.Names.Item(Index).Value
Obtains the value of a single Name object by using the Value property.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index).Valueexpression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Obtain a single Name object. const name = await names.Item(1); //Obtain the value of the Name object. const value = await name.Value; console.log(value); }
ActiveWorkbook.ActiveSheet.Names.Item(Index).RefersToRange
Only JS-SDK V1.1.19 and later support this feature.
Obtains the Range object that the Name object refers to by using the RefersToRange property.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index).RefersToRangeexpression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Name object const names = await activeSheet.Names; // Single Name object const name = await names.Item(1); // Return the Range object. const range = await name.RefersToRange; }
Names
ActiveWorkbook.ActiveSheet.Names
Obtains all names of the active worksheet.
Syntax
expression.ActiveWorkbook.ActiveSheet.Namesexpression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; }
Methods
ActiveWorkbook.ActiveSheet.Names.Add()
Defines a new name for a specific cell by using the Add() method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Add({ Name, RefersTo })expression: an Application object
Parameters
Property
Data type
Required
Description
Name
String
Yes
The new name.
RefersTo
Number
No
The cell for which you want to specify the new name.
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Specify a new name for cell A1. names.Add('New table', 'A1'); }
ActiveWorkbook.ActiveSheet.Names.ValidNewName()
Checks whether a specific name is valid by using the ValidNewName() method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.ValidNewName({ Name })expression: an Application object
Parameters
Property
Data type
Required
Description
Name
String
Yes
The name.
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Check whether the name is valid. names.ValidNewName('New table'); }
ActiveWorkbook.ActiveSheet.Names.Item(Index)
Only JS-SDK V1.1.3 and later support this feature.
Obtains the name at the specified Index by using the Item property.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Item(Index)expression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Name object const names = await activeSheet.Names; // Single Name object const name = await names.Item(1); }
Properties
ActiveWorkbook.ActiveSheet.Names.Count
Obtains the number of names in the active worksheet by using the Count property.
Syntax
expression.ActiveWorkbook.ActiveSheet.Names.Countexpression: an Application object
Example
async function example() { await instance.ready(); const app = instance.Application; //Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; //Obtain all names in the active worksheet. const names = await activeSheet.Names; //Obtain the number of names. const count = await names.Count; console.log(count); }