コード例 #1
0
 void setType(int type) {
   switch (type) {
     case CELL_TYPE_NUMERIC:
       {
         _value = new NumericValue();
         break;
       }
     case CELL_TYPE_STRING:
       {
         PlainStringValue sval = new PlainStringValue();
         if (_value != null) {
           // if a cell is not blank then convert the old value to string
           String str = convertCellValueToString();
           sval.setValue(str);
         }
         _value = sval;
         break;
       }
     case CELL_TYPE_FORMULA:
       {
         _value = new NumericFormulaValue();
         break;
       }
     case CELL_TYPE_BLANK:
       {
         _value = new BlankValue();
         break;
       }
     case CELL_TYPE_BOOLEAN:
       {
         BooleanValue bval = new BooleanValue();
         if (_value != null) {
           // if a cell is not blank then convert the old value to string
           boolean val = convertCellValueToBoolean();
           bval.setValue(val);
         }
         _value = bval;
         break;
       }
     case CELL_TYPE_ERROR:
       {
         _value = new ErrorValue();
         break;
       }
     default:
       {
         throw new IllegalArgumentException("Illegal type " + type);
       }
   }
 }
コード例 #2
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);
 }