コード例 #1
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);
   }
 }
コード例 #2
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.
     _cell.setT(STCellType.E);
     _cell.setV(FormulaError.DIV0.getString());
   } else if (Double.isNaN(value)) {
     // Excel does not support Not-a-Number (NaN),
     // instead it immediately generates an #NUM! error.
     _cell.setT(STCellType.E);
     _cell.setV(FormulaError.NUM.getString());
   } else {
     _cell.setT(STCellType.N);
     _cell.setV(String.valueOf(value));
   }
 }