Class CellUtils

java.lang.Object
org.xlsx4j.model.CellUtils

public class CellUtils
extends java.lang.Object
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int CELL_TYPE_BLANK
    Blank Cell type (3)
    static int CELL_TYPE_BOOLEAN
    Boolean Cell type (4)
    static int CELL_TYPE_ERROR
    Error Cell type (5)
    static int CELL_TYPE_FORMULA
    Formula Cell type (2)
    static int CELL_TYPE_NUMERIC
    Numeric Cell type (0)
    static int CELL_TYPE_STRING
    String Cell type (1)
    protected static org.slf4j.Logger log  
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected CellUtils()  
  • Method Summary

    Modifier and Type Method Description
    static boolean getBooleanCellValue​(Cell _cell)
    Get the value of the cell as a boolean.
    static CTCellStyle getCellStyle​(Cell _cell)
    Return the cell's style.
    static int getCellType​(Cell _cell)
    Return the cell type.
    static java.util.Date getDateCellValue​(Cell _cell)
    Get the value of the cell as a date.
    static long getNumberFormatIndex​(Cell _cell)
    Get the index of the number format (numFmt) record used by this cell format.
    static java.lang.String getNumberFormatString​(Cell _cell)
    Get the contents of the format string, by looking up the StylesSource
    static double getNumericCellValue​(Cell _cell)
    Get the value of the cell as a number.
    static java.lang.RuntimeException typeMismatch​(int expectedTypeCode, int actualTypeCode, boolean isFormulaCell)
    Used to help format error messages

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getNumericCellValue

      public static double getNumericCellValue​(Cell _cell)
      Get the value of the cell as a number.

      For strings we throw an exception. For blank cells we return a 0. For formulas or error cells we return the precalculated value;

      Returns:
      the value of the cell as a number
      Throws:
      java.lang.IllegalStateException - if the cell type returned by #getCellType() is CELL_TYPE_STRING
      java.lang.NumberFormatException - if the cell value isn't a parsable double.
      See Also:
      for turning this number into a string similar to that which Excel would render this number as.
    • typeMismatch

      public static java.lang.RuntimeException typeMismatch​(int expectedTypeCode, int actualTypeCode, boolean isFormulaCell)
      Used to help format error messages
    • getCellType

      public static int getCellType​(Cell _cell)
      Return the cell type.
      Returns:
      the cell type
      See Also:
      Cell#CELL_TYPE_BLANK, Cell#CELL_TYPE_NUMERIC, Cell#CELL_TYPE_STRING, Cell#CELL_TYPE_FORMULA, Cell#CELL_TYPE_BOOLEAN, Cell#CELL_TYPE_ERROR
    • getCellStyle

      public static CTCellStyle getCellStyle​(Cell _cell)
      Return the cell's style.
      Returns:
      the cell's style.
    • getNumberFormatIndex

      public static long getNumberFormatIndex​(Cell _cell)
      Get the index of the number format (numFmt) record used by this cell format.
      Returns:
      the index of the number format
    • getNumberFormatString

      public static java.lang.String getNumberFormatString​(Cell _cell)
      Get the contents of the format string, by looking up the StylesSource
      Returns:
      the number format string
    • getDateCellValue

      public static java.util.Date getDateCellValue​(Cell _cell)
      Get the value of the cell as a date.

      For strings we throw an exception. For blank cells we return a null.

      Returns:
      the value of the cell as a date
      Throws:
      java.lang.IllegalStateException - if the cell type returned by #getCellType() is CELL_TYPE_STRING
      java.lang.NumberFormatException - if the cell value isn't a parsable double.
      See Also:
      for formatting this date into a string similar to how excel does.
    • getBooleanCellValue

      public static boolean getBooleanCellValue​(Cell _cell)
      Get the value of the cell as a boolean.

      For strings, numbers, and errors, we throw an exception. For blank cells we return a false.

      Returns:
      the value of the cell as a boolean
      Throws:
      java.lang.IllegalStateException - if the cell type returned by #getCellType() is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA