Interface CellValue

All Known Implementing Classes:
CellValue.Array, CellValue.Blank, CellValue.Bool, CellValue.Error, CellValue.Number, CellValue.Text

One cell's value: a number, text, boolean, error or blank, or a matrix passed to and from a user-defined function. Immutable.

Values are produced when reading a Range or Sheet.value(int, int) and consumed when writing. A value is a snapshot: it does not follow later edits to the cell, and changing a cell means writing a new value. Switch on the record type to read it:


 CellValue v = sheet.cell(0, 0).value();
 if (v instanceof CellValue.Number n) {
     double d = n.value();
 } else if (v instanceof CellValue.Error e) {
     String shown = e.display(); // e.g. "#DIV/0!"
 }
 

Dates are numbers (Excel date serials); see Cell.dateValue().

A formula error (e.g. #DIV/0!) is data, carried by CellValue.Error — it is never thrown as an exception.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A rectangular, row-major matrix of scalar values (rows[r][c]).
    static final record 
    The empty cell value; use the shared BLANK.
    static final record 
    A boolean cell value.
    static final record 
    An error cell value, identified by its Excel ERROR.TYPE code (see error(int) for the codes).
    static final record 
    A numeric cell value.
    static final record 
    A text cell value.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CellValue.Blank
    The value of an empty cell.
    static final CellValue.Bool
    The boolean FALSE.
    static final CellValue.Bool
    The boolean TRUE.
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static CellValue
    array(CellValue[][] rows)
    A row-major matrix value (see CellValue.Array) — the shape of a range argument to a typed user-defined function, or of an array result returned from one.
    static CellValue
    Returns BLANK, the value of an empty cell.
    static CellValue
    bool(boolean value)
    A boolean value: TRUE or FALSE.
    static CellValue
    error(int code)
    An error value from its Excel ERROR.TYPE code: 1 #NULL!, 2 #DIV/0!, 3 #VALUE!, 4 #REF!, 5 #NAME?, 6 #NUM!, 7 #N/A, 8 #GETTING_DATA, 9 #SPILL!, 14 #CALC!.
    static String
    errorString(int code)
    Maps an Excel ERROR.TYPE code to its display string.
    static CellValue
    number(double value)
    A numeric value.
    static CellValue
    text(String value)
    A text value, stored as typed: a numeric-looking string stays text.
  • Field Details

    • BLANK

      static final CellValue.Blank BLANK
      The value of an empty cell. Writing it clears the cell's value and formula.
    • TRUE

      static final CellValue.Bool TRUE
      The boolean TRUE.
    • FALSE

      static final CellValue.Bool FALSE
      The boolean FALSE.
  • Method Details

    • number

      static CellValue number(double value)
      A numeric value. Excel stores integers, decimals and dates alike as 64-bit floating point numbers.
    • text

      static CellValue text(String value)
      A text value, stored as typed: a numeric-looking string stays text.
    • bool

      static CellValue bool(boolean value)
      A boolean value: TRUE or FALSE.
    • error

      static CellValue error(int code)
      An error value from its Excel ERROR.TYPE code: 1 #NULL!, 2 #DIV/0!, 3 #VALUE!, 4 #REF!, 5 #NAME?, 6 #NUM!, 7 #N/A, 8 #GETTING_DATA, 9 #SPILL!, 14 #CALC!. Any other code is written as #VALUE!.
    • blank

      static CellValue blank()
      Returns BLANK, the value of an empty cell.
    • array

      static CellValue array(CellValue[][] rows)
      A row-major matrix value (see CellValue.Array) — the shape of a range argument to a typed user-defined function, or of an array result returned from one. Writing it to a cell throws IllegalArgumentException.
      Parameters:
      rows - the rows, each of the same length; stored as given, not copied
    • errorString

      static String errorString(int code)
      Maps an Excel ERROR.TYPE code to its display string. Unknown codes give #VALUE!, as in the engine.