/** * Get the value of the cell as an error code. * * <p>For strings, numbers, and booleans, we throw an exception. For blank cells we return a 0. * * @return the value of the cell as an error code * @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't * CELL_TYPE_ERROR * @see FormulaError */ public byte getErrorCellValue() { String code = getErrorCellString(); if (code == null) { return 0; } return FormulaError.forString(code).getCode(); }
private String convertCellValueToString() { int cellType = getCellType(); switch (cellType) { case CELL_TYPE_BLANK: return ""; case CELL_TYPE_BOOLEAN: return getBooleanCellValue() ? "TRUE" : "FALSE"; case CELL_TYPE_STRING: return getStringCellValue(); case CELL_TYPE_NUMERIC: case CELL_TYPE_ERROR: byte errVal = getErrorCellValue(); return FormulaError.forInt(errVal).getString(); case CELL_TYPE_FORMULA: return ""; default: throw new IllegalStateException("Unexpected cell type (" + cellType + ")"); } }
/** * Set a error value for the cell * * @param error the error value to set this cell to. For formulas we'll set the precalculated * value , for errors we'll set its value. For other types we will change the cell to an error * cell and set its value. */ public void setCellErrorValue(FormulaError error) { _cell.setT(STCellType.E); _cell.setV(error.getString()); }
/** * Set a error value for the cell * * @param errorCode the error value to set this cell to. For formulas we'll set the precalculated * value , for errors we'll set its value. For other types we will change the cell to an error * cell and set its value. * @see FormulaError */ public void setCellErrorValue(byte errorCode) { FormulaError error = FormulaError.forInt(errorCode); setCellErrorValue(error); }