[]
        
(Showing Draft Content)

INames

Interface INames


public interface INames
Represents a collection of IName objects that store defined names.

Each IName object represents a defined name for a cell, cell range, formula, or constant. Names can be either built-in names, such as Database, Print_Area, and Auto_Open, or custom names created in workbook or worksheet scope.


 INames names = workbook.getNames();
 names.add("SalesData", "A1:B3");
 IName salesData = names.get("SalesData");
 
  • Method Summary

    Modifier and Type
    Method
    Description
    add(String name, String refersTo)
    Defines a new name.
    void
    Clears the IName collection.
    boolean
    Determines whether a name is contained in INames.
    void
    Generates a collection of defined names from the JSON string.
    get(int index)
    Returns the IName object from a collection.
    get(String name)
    Returns the IName object from a collection.
    int
    Returns the number of objects in the collection.
    Generates the json string from the defined names.
  • Method Details

    • getCount

      int getCount()
      Returns the number of objects in the collection.

      For an INames collection, the objects are defined names.

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       int count = names.getCount();
       
      Returns:
      The number of defined names in the collection.
    • add

      IName add(String name, String refersTo)
      Defines a new name. Returns the IName object.

      Uses A1-style notation in refersTo to define what the name refers to, such as a cell, range, formula, or constant.

      
       INames names = worksheet.getNames();
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100},
           {"Total", 200}
       });
       IName salesData = names.add("SalesData", "A1:B3");
       
      Parameters:
      name - The text to use as the name. Names cannot include spaces and cannot look like cell references.
      refersTo - The A1-style reference string that describes what the name refers to.
      Returns:
      Returns a new IName object.
    • contains

      boolean contains(String name)
      Determines whether a name is contained in INames.

      Use this method to check whether the collection already includes a defined name before retrieving it with get(String) or adding a new one.

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       boolean contains = names.contains("SalesRange");
       
      Parameters:
      name - The name to look for in the collection.
      Returns:
      true if INames contains the specified name; otherwise, false.
    • get

      IName get(String name)
      Returns the IName object from a collection.

      Use this method to retrieve a defined name by its name.

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       IName name = names.get("SalesRange");
       
      Parameters:
      name - Specifies the name of an element in the collection.
      Returns:
      The IName object from the collection.
    • get

      IName get(int index)
      Returns the IName object from a collection.

      Use the zero-based index of the defined name in this collection to retrieve a specific name object.

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       IName name = names.get(0);
       String definedName = name.getName();
       
      Parameters:
      index - Specifies the index of an element in the collection.
      Returns:
      The IName object at the specified index in the collection.
    • clear

      void clear()
      Clears the IName collection.

      Removes all defined names from this collection, including names in the current workbook or worksheet scope represented by this INames instance.

      
       worksheet.getRange("A1").setValue("North");
       INames names = worksheet.getNames();
       names.add("RegionName", "=Sheet1!$A$1");
       names.clear();
       
    • fromJson

      void fromJson(String json)
      Generates a collection of defined names from the JSON string.

      Use this method to import defined names into the collection from JSON data, such as data previously generated by toJson().

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       String json = names.toJson();
       names.clear();
       names.fromJson(json);
       
      Parameters:
      json - The JSON string that contains defined names.
    • toJson

      String toJson()
      Generates the json string from the defined names.

      The returned string serializes the current collection of defined names and can be used with fromJson(String) to restore the collection later.

      
       INames names = workbook.getNames();
       names.add("SalesRange", "=Sheet1!$A$1:$A$5");
       String json = names.toJson();
       
      Returns:
      The json string that represents the defined names.