Class CellUtils

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

public class CellUtils extends Object
  • Field Details

    • log

      protected static org.slf4j.Logger log
    • CELL_TYPE_NUMERIC

      public static final int CELL_TYPE_NUMERIC
      Numeric Cell type (0)
      See Also:
    • CELL_TYPE_STRING

      public static final int CELL_TYPE_STRING
      String Cell type (1)
      See Also:
    • CELL_TYPE_FORMULA

      public static final int CELL_TYPE_FORMULA
      Formula Cell type (2)
      See Also:
    • CELL_TYPE_BLANK

      public static final int CELL_TYPE_BLANK
      Blank Cell type (3)
      See Also:
    • CELL_TYPE_BOOLEAN

      public static final int CELL_TYPE_BOOLEAN
      Boolean Cell type (4)
      See Also:
    • CELL_TYPE_ERROR

      public static final int CELL_TYPE_ERROR
      Error Cell type (5)
      See Also:
  • Constructor Details

    • CellUtils

      protected CellUtils()
  • 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:
      IllegalStateException - if the cell type returned by #getCellType() is CELL_TYPE_STRING
      NumberFormatException - if the cell value isn't a parsable double.
      See Also:
    • typeMismatch

      public static 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 String getNumberFormatString(Cell _cell)
      Get the contents of the format string, by looking up the StylesSource
      Returns:
      the number format string
    • getDateCellValue

      public static 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:
      IllegalStateException - if the cell type returned by #getCellType() is CELL_TYPE_STRING
      NumberFormatException - if the cell value isn't a parsable double.
      See Also:
    • 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:
      IllegalStateException - if the cell type returned by #getCellType() is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA