示例#1
0
  /**
   * Only valid for formula cells
   *
   * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING}, {@link
   *     #CELL_TYPE_BOOLEAN}, {@link #CELL_TYPE_ERROR}) depending on the cached value of the formula
   */
  public int getCachedFormulaResultType() {
    if (_value.getType() != CELL_TYPE_FORMULA) {
      throw new IllegalStateException("Only formula cells have cached results");
    }

    return ((FormulaValue) _value).getFormulaType();
  }
示例#2
0
 void ensureTypeOrFormulaType(int type) {
   assert type == CELL_TYPE_NUMERIC
       || type == CELL_TYPE_STRING
       || type == CELL_TYPE_BOOLEAN
       || type == CELL_TYPE_ERROR;
   if (_value.getType() == type) {
     if (type == CELL_TYPE_STRING && ((StringValue) _value).isRichText())
       setType(CELL_TYPE_STRING);
     return;
   }
   if (_value.getType() == CELL_TYPE_FORMULA) {
     if (((FormulaValue) _value).getFormulaType() == type) return;
     setFormulaType(type); // once a formula, always a formula
     return;
   }
   setType(type);
 }
示例#3
0
 /**
  * Set a numeric value for the cell
  *
  * @param value the numeric value to set this cell to. For formulas we'll set the precalculated
  *     value, for numerics we'll set its value. For other types we will change the cell to a
  *     numeric cell and set its value.
  */
 public void setCellValue(double value) {
   if (Double.isInfinite(value)) {
     // Excel does not support positive/negative infinities,
     // rather, it gives a #DIV/0! error in these cases.
     setCellErrorValue(FormulaError.DIV0.getCode());
   } else if (Double.isNaN(value)) {
     setCellErrorValue(FormulaError.NUM.getCode());
   } else {
     ensureTypeOrFormulaType(CELL_TYPE_NUMERIC);
     if (_value.getType() == CELL_TYPE_FORMULA)
       ((NumericFormulaValue) _value).setPreEvaluatedValue(value);
     else ((NumericValue) _value).setValue(value);
   }
 }
示例#4
0
 void ensureFormulaType(int type) {
   if (_value.getType() != CELL_TYPE_FORMULA || ((FormulaValue) _value).getFormulaType() != type)
     setFormulaType(type);
 }
示例#5
0
 void ensureType(int type) {
   if (_value.getType() != type) setType(type);
 }
示例#6
0
 void ensureRichTextStringType() {
   if (_value.getType() != CELL_TYPE_STRING || !((StringValue) _value).isRichText())
     _value = new RichTextValue();
 }
示例#7
0
 void ensurePlainStringType() {
   if (_value.getType() != CELL_TYPE_STRING || ((StringValue) _value).isRichText())
     _value = new PlainStringValue();
 }
示例#8
0
 /**
  * Set a error value for the cell
  *
  * @param value 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 org.zkoss.poi.ss.usermodel.FormulaError
  */
 public void setCellErrorValue(byte value) {
   ensureType(CELL_TYPE_ERROR);
   if (_value.getType() == CELL_TYPE_FORMULA)
     ((ErrorFormulaValue) _value).setPreEvaluatedValue(value);
   else ((ErrorValue) _value).setValue(value);
 }
示例#9
0
 /**
  * Set a boolean value for the cell
  *
  * @param value the boolean value to set this cell to. For formulas we'll set the precalculated
  *     value, for booleans we'll set its value. For other types we will change the cell to a
  *     boolean cell and set its value.
  */
 public void setCellValue(boolean value) {
   ensureTypeOrFormulaType(CELL_TYPE_BOOLEAN);
   if (_value.getType() == CELL_TYPE_FORMULA)
     ((BooleanFormulaValue) _value).setPreEvaluatedValue(value);
   else ((BooleanValue) _value).setValue(value);
 }
示例#10
0
 /**
  * Return a formula for the cell, for example, <code>SUM(C4:E4)</code>
  *
  * @return a formula for the cell
  * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not
  *     CELL_TYPE_FORMULA
  */
 public String getCellFormula() {
   if (_value.getType() != CELL_TYPE_FORMULA)
     throw typeMismatch(CELL_TYPE_FORMULA, _value.getType(), false);
   return ((FormulaValue) _value).getValue();
 }
示例#11
0
 /**
  * Set a string value for the cell.
  *
  * @param value value to set the cell to. For formulas we'll set the formula string, for String
  *     cells we'll set its value. For other types we will change the cell to a string cell and set
  *     its value. If value is null then we will change the cell to a Blank cell.
  */
 public void setCellValue(String value) {
   ensureTypeOrFormulaType(CELL_TYPE_STRING);
   if (_value.getType() == CELL_TYPE_FORMULA)
     ((StringFormulaValue) _value).setPreEvaluatedValue(value);
   else ((PlainStringValue) _value).setValue(value);
 }
示例#12
0
 /**
  * Return the cell type.
  *
  * @return the cell type
  * @see Cell#CELL_TYPE_BLANK
  * @see Cell#CELL_TYPE_NUMERIC
  * @see Cell#CELL_TYPE_STRING
  * @see Cell#CELL_TYPE_FORMULA
  * @see Cell#CELL_TYPE_BOOLEAN
  * @see Cell#CELL_TYPE_ERROR
  */
 public int getCellType() {
   return _value.getType();
 }