}
/**
- * set the error value for the cell
+ * set the error value for the cell. See {@link FormulaError} for valid codes.
*
* @param value error representing the error value
* this value can only be 0,7,15,23,29,36 or 42
* see bugzilla bug 16560 for an explanation
*/
public void setValue(byte value) {
- switch(FormulaError.forInt(value)) {
+ setValue(FormulaError.forInt(value));
+ }
+
+ /**
+ * set the error value for the cell
+ *
+ * @param value error representing the error value
+ * this value can only be 0,7,15,23,29,36 or 42
+ * see bugzilla bug 16560 for an explanation
+ */
+ public void setValue(FormulaError value) {
+ switch(value) {
case NULL:
case DIV0:
case VALUE:
case NAME:
case NUM:
case NA:
- _value = value;
+ _value = value.getCode();
_isError = true;
return;
default:
- throw new IllegalArgumentException("Error Value can only be 0,7,15,23,29,36 or 42. It cannot be "+value);
+ throw new IllegalArgumentException("Error Value can only be 0,7,15,23,29,36 or 42. It cannot be "+value.getCode()+" ("+value+")");
}
}
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.hssf.util.CellRangeAddress8Bit;
import org.apache.poi.ss.formula.ptg.ExpPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.hssf.util.CellRangeAddress8Bit;
-import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.formula.Formula;
+import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.CellReference;
/**
* The formula record aggregate is used to join together the formula record and it's
_stringRecord = null;
_formulaRecord.setCachedResultErrorCode(errorCode);
}
+ public void setCachedErrorResult(FormulaError error) {
+ setCachedErrorResult(error.getCode());
+ }
public void setCachedDoubleResult(double value) {
_stringRecord = null;
_formulaRecord.setValue(value);
int row=_record.getRow();
short col=_record.getColumn();
short styleIndex=_record.getXFIndex();
- byte code = error.getCode();
switch (_cellType) {
default:
setCellType(CELL_TYPE_ERROR, false, row, col, styleIndex);
// fall through
case CELL_TYPE_ERROR:
- (( BoolErrRecord ) _record).setValue(code);
+ (( BoolErrRecord ) _record).setValue(error);
break;
case CELL_TYPE_FORMULA:
- ((FormulaRecordAggregate)_record).setCachedErrorResult(code);
+ ((FormulaRecordAggregate)_record).setCachedErrorResult(error.getCode());
break;
}
}