]> source.dussan.org Git - poi.git/commitdiff
add HSSFCell.setCachedErrorResult(FormulaError)
authorJaven O'Neal <onealj@apache.org>
Mon, 13 Jun 2016 10:53:03 +0000 (10:53 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 13 Jun 2016 10:53:03 +0000 (10:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748174 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/BoolErrRecord.java
src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java

index 92359e1f31278218b0d34a0ad2df263a96535adb..3ff786ad91d1c826171fd1e15efda6718ac40043 100644 (file)
@@ -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+")");
                }
        }
 
index e0dfef4770e9d2c3dd6ad976740672945ae95a55..4382d99c456d287b8a23f235a02a07fee1a81ec8 100644 (file)
@@ -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);
index 1d97422888d4e73974f0a6ff533d1b84bdb0cf9d..bf317b01dc61e82713d57a53245bc5ae36f879a3 100644 (file)
@@ -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;
         }
     }