Class NamedRange

java.lang.Object
io.keikai.axyra.sheets.NamedRange

public final class NamedRange extends Object
A defined name (named range). sheetScope is the 0-based sheet index it is scoped to, or -1 for workbook scope.

Instances handed out by Workbook.names() and Workbook.findName(String) stay attached to their workbook, so asRange() resolves straight to the cells the name points at — a template can be authored in Excel and filled in by key:


 wb.findName("TaxRate").asRange().setFormula("=0.07");
 CellValue[][] data = wb.findName("Inputs").asRange().values();
 

A NamedRange is a snapshot of the definition: it does not follow a later change to the name in the workbook. Two names are equal when their name, formula and scope match; the workbook they came from is not part of that comparison.

  • Constructor Summary

    Constructors
    Constructor
    Description
    NamedRange(String name, String formula, int sheetScope)
    A detached name — one that carries no workbook, so asRange() has nothing to resolve against.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the cells this name points at, resolved from the formula held by this object.
    boolean
     
    Returns the formula the name stands for: for a named range, a reference such as "Sheet1!$A$1:$B$10"; for a named constant, its value.
    int
     
    boolean
    Returns whether this name is workbook-scoped, that is visible on every sheet.
    Returns the defined name, as written in the workbook.
    int
    Returns the 0-based index of the sheet this name is scoped to, or -1 for workbook scope.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • NamedRange

      public NamedRange(String name, String formula, int sheetScope)
      A detached name — one that carries no workbook, so asRange() has nothing to resolve against. Use Workbook.findName(String) to obtain an attached one.
      Parameters:
      name - the defined name
      formula - the reference or constant the name stands for, e.g. "Sheet1!$A$1:$B$10"
      sheetScope - the 0-based index of the sheet the name is scoped to, or -1 for workbook scope
  • Method Details

    • name

      public String name()
      Returns the defined name, as written in the workbook.
    • formula

      public String formula()
      Returns the formula the name stands for: for a named range, a reference such as "Sheet1!$A$1:$B$10"; for a named constant, its value.
    • sheetScope

      public int sheetScope()
      Returns the 0-based index of the sheet this name is scoped to, or -1 for workbook scope.
    • isWorkbookScoped

      public boolean isWorkbookScoped()
      Returns whether this name is workbook-scoped, that is visible on every sheet.
    • asRange

      public Range asRange()
      Returns the cells this name points at, resolved from the formula held by this object.

      A sheet-scoped name whose formula carries no Sheet! qualifier resolves against the sheet it is scoped to. Whole-column and whole-row names (Sheet1!$B:$B) expand to the grid's limits.

      Throws:
      IllegalStateException - if this name is detached from its workbook (built with the public constructor rather than read from a workbook)
      IllegalArgumentException - if the name does not resolve to a single rectangular area on a sheet of this workbook — a named constant, a multi-area union, an external or 3-D reference
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object