From e61e3464362627e89136e718ca273c16b0e017e4 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 13 Jun 2016 10:53:03 +0000 Subject: [PATCH] add HSSFCell.setCachedErrorResult(FormulaError) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748174 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/BoolErrRecord.java | 19 +++++++++++++++---- .../aggregates/FormulaRecordAggregate.java | 8 ++++++-- .../apache/poi/hssf/usermodel/HSSFCell.java | 5 ++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/BoolErrRecord.java b/src/java/org/apache/poi/hssf/record/BoolErrRecord.java index 92359e1f31..3ff786ad91 100644 --- a/src/java/org/apache/poi/hssf/record/BoolErrRecord.java +++ b/src/java/org/apache/poi/hssf/record/BoolErrRecord.java @@ -81,14 +81,25 @@ public final class BoolErrRecord extends CellRecord implements Cloneable { } /** - * 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: @@ -96,11 +107,11 @@ public final class BoolErrRecord extends CellRecord implements Cloneable { 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+")"); } } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java index e0dfef4770..4382d99c45 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java @@ -24,12 +24,13 @@ import org.apache.poi.hssf.record.Record; 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 @@ -180,6 +181,9 @@ public final class FormulaRecordAggregate extends RecordAggregate implements Cel _stringRecord = null; _formulaRecord.setCachedResultErrorCode(errorCode); } + public void setCachedErrorResult(FormulaError error) { + setCachedErrorResult(error.getCode()); + } public void setCachedDoubleResult(double value) { _stringRecord = null; _formulaRecord.setValue(value); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 1d97422888..bf317b01dc 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -791,16 +791,15 @@ public class HSSFCell implements Cell { 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; } } -- 2.39.5