示例#1
0
 /**
  * Get the value of the cell as a number.
  *
  * <p>For strings we throw an exception. For blank cells we return a 0. For formulas or error
  * cells we return the precalculated value;
  *
  * @return the value of the cell as a number
  * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is
  *     CELL_TYPE_STRING
  * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
  * @see org.zkoss.poi.ss.usermodel.DataFormatter for turning this number into a string similar to
  *     that which Excel would render this number as.
  */
 public double getNumericCellValue() {
   int cellType = getCellType();
   switch (cellType) {
     case CELL_TYPE_BLANK:
       return 0.0;
     case CELL_TYPE_FORMULA:
       {
         FormulaValue fv = (FormulaValue) _value;
         if (fv.getFormulaType() != CELL_TYPE_NUMERIC)
           throw typeMismatch(CELL_TYPE_NUMERIC, CELL_TYPE_FORMULA, false);
         return ((NumericFormulaValue) _value).getPreEvaluatedValue();
       }
     case CELL_TYPE_NUMERIC:
       return ((NumericValue) _value).getValue();
     default:
       throw typeMismatch(CELL_TYPE_NUMERIC, cellType, false);
   }
 }
示例#2
0
 /**
  * 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 org.zkoss.poi.ss.usermodel.FormulaError for error codes
  */
 public byte getErrorCellValue() {
   int cellType = getCellType();
   switch (cellType) {
     case CELL_TYPE_BLANK:
       return 0;
     case CELL_TYPE_FORMULA:
       {
         FormulaValue fv = (FormulaValue) _value;
         if (fv.getFormulaType() != CELL_TYPE_ERROR)
           throw typeMismatch(CELL_TYPE_ERROR, CELL_TYPE_FORMULA, false);
         return ((ErrorFormulaValue) _value).getPreEvaluatedValue();
       }
     case CELL_TYPE_ERROR:
       {
         return ((ErrorValue) _value).getValue();
       }
     default:
       throw typeMismatch(CELL_TYPE_ERROR, cellType, false);
   }
 }
示例#3
0
 /**
  * Get the value of the cell as a boolean.
  *
  * <p>For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
  *
  * @return the value of the cell as a boolean
  * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not
  *     CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA
  */
 public boolean getBooleanCellValue() {
   int cellType = getCellType();
   switch (cellType) {
     case CELL_TYPE_BLANK:
       return false;
     case CELL_TYPE_FORMULA:
       {
         FormulaValue fv = (FormulaValue) _value;
         if (fv.getFormulaType() != CELL_TYPE_BOOLEAN)
           throw typeMismatch(CELL_TYPE_BOOLEAN, CELL_TYPE_FORMULA, false);
         return ((BooleanFormulaValue) _value).getPreEvaluatedValue();
       }
     case CELL_TYPE_BOOLEAN:
       {
         return ((BooleanValue) _value).getValue();
       }
     default:
       throw typeMismatch(CELL_TYPE_BOOLEAN, cellType, false);
   }
 }
示例#4
0
 /**
  * Get the value of the cell as a string
  *
  * <p>For numeric cells we throw an exception. For blank cells we return an empty string. For
  * formulaCells that are not string Formulas, we throw an exception.
  *
  * @return the value of the cell as a string
  */
 public String getStringCellValue() {
   int cellType = getCellType();
   switch (cellType) {
     case CELL_TYPE_BLANK:
       return "";
     case CELL_TYPE_FORMULA:
       {
         FormulaValue fv = (FormulaValue) _value;
         if (fv.getFormulaType() != CELL_TYPE_STRING)
           throw typeMismatch(CELL_TYPE_STRING, CELL_TYPE_FORMULA, false);
         return ((StringFormulaValue) _value).getPreEvaluatedValue();
       }
     case CELL_TYPE_STRING:
       {
         if (((StringValue) _value).isRichText())
           return ((RichTextValue) _value).getValue().getString();
         else return ((PlainStringValue) _value).getValue();
       }
     default:
       throw typeMismatch(CELL_TYPE_STRING, cellType, false);
   }
 }