Package org.xlsx4j.model
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 intCELL_TYPE_BLANKBlank Cell type (3)static intCELL_TYPE_BOOLEANBoolean Cell type (4)static intCELL_TYPE_ERRORError Cell type (5)static intCELL_TYPE_FORMULAFormula Cell type (2)static intCELL_TYPE_NUMERICNumeric Cell type (0)static intCELL_TYPE_STRINGString Cell type (1)protected static org.slf4j.Loggerlog -
Constructor Summary
Constructors Modifier Constructor Description protectedCellUtils() -
Method Summary
Modifier and Type Method Description static booleangetBooleanCellValue(Cell _cell)Get the value of the cell as a boolean.static CTCellStylegetCellStyle(Cell _cell)Return the cell's style.static intgetCellType(Cell _cell)Return the cell type.static java.util.DategetDateCellValue(Cell _cell)Get the value of the cell as a date.static longgetNumberFormatIndex(Cell _cell)Get the index of the number format (numFmt) record used by this cell format.static java.lang.StringgetNumberFormatString(Cell _cell)Get the contents of the format string, by looking up the StylesSourcestatic doublegetNumericCellValue(Cell _cell)Get the value of the cell as a number.static java.lang.RuntimeExceptiontypeMismatch(int expectedTypeCode, int actualTypeCode, boolean isFormulaCell)Used to help format error messages
-
Field Details
-
log
protected static org.slf4j.Logger log -
CELL_TYPE_NUMERIC
public static final int CELL_TYPE_NUMERICNumeric Cell type (0)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
CELL_TYPE_STRING
public static final int CELL_TYPE_STRINGString Cell type (1)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
CELL_TYPE_FORMULA
public static final int CELL_TYPE_FORMULAFormula Cell type (2)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
CELL_TYPE_BLANK
public static final int CELL_TYPE_BLANKBlank Cell type (3)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
CELL_TYPE_BOOLEAN
public static final int CELL_TYPE_BOOLEANBoolean Cell type (4)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
CELL_TYPE_ERROR
public static final int CELL_TYPE_ERRORError Cell type (5)- See Also:
#setCellType(int),#getCellType(), Constant Field Values
-
-
Constructor Details
-
CellUtils
protected CellUtils()
-
-
Method Details
-
getNumericCellValue
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_STRINGjava.lang.NumberFormatException- if the cell value isn't a parsabledouble.- 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
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
Return the cell's style.- Returns:
- the cell's style.
-
getNumberFormatIndex
Get the index of the number format (numFmt) record used by this cell format.- Returns:
- the index of the number format
-
getNumberFormatString
Get the contents of the format string, by looking up the StylesSource- Returns:
- the number format string
-
getDateCellValue
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_STRINGjava.lang.NumberFormatException- if the cell value isn't a parsabledouble.- See Also:
for formatting this date into a string similar to how excel does.
-
getBooleanCellValue
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
-