diff options
author | Vladislav Galas <gallon@apache.org> | 2019-01-26 23:19:53 +0000 |
---|---|---|
committer | Vladislav Galas <gallon@apache.org> | 2019-01-26 23:19:53 +0000 |
commit | 5da229797f116457f2fdefad95306399b9757535 (patch) | |
tree | 6efc71387e03191b583927b402dfef43ec20c4f9 /src/java/org | |
parent | 70b4b88a3ab2b35f078d91972ffa2641282b8bdd (diff) | |
download | poi-5da229797f116457f2fdefad95306399b9757535.tar.gz poi-5da229797f116457f2fdefad95306399b9757535.zip |
pulled *Cell.setCellValue(double) to the common base
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1852253 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 50 | ||||
-rw-r--r-- | src/java/org/apache/poi/ss/usermodel/Cell.java | 5 | ||||
-rw-r--r-- | src/java/org/apache/poi/ss/usermodel/CellBase.java | 25 |
3 files changed, 45 insertions, 35 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index b1cf8a4845..7abfe59d20 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -50,7 +50,6 @@ import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.RichTextString; -import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.NumberToTextConverter; @@ -420,41 +419,26 @@ public class HSSFCell extends CellBase { } /** - * 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. + * {@inheritDoc} */ - @SuppressWarnings("fallthrough") @Override - 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)){ - // Excel does not support Not-a-Number (NaN), - // instead it immediately generates a #NUM! error. - setCellErrorValue(FormulaError.NUM.getCode()); - } else { - int row=_record.getRow(); - short col=_record.getColumn(); - short styleIndex=_record.getXFIndex(); - - switch (_cellType) { - default: - setCellType(CellType.NUMERIC, false, row, col, styleIndex); - // fall through - case NUMERIC: - (( NumberRecord ) _record).setValue(value); - break; - case FORMULA: - ((FormulaRecordAggregate)_record).setCachedDoubleResult(value); - break; - } + @SuppressWarnings("fallthrough") + protected void setCellValueImpl(double value) { + switch (_cellType) { + default: + setCellType(CellType.NUMERIC, + false, + _record.getRow(), + _record.getColumn(), + _record.getXFIndex()); + // fall through + case NUMERIC: + ((NumberRecord)_record).setValue(value); + break; + case FORMULA: + ((FormulaRecordAggregate)_record).setCachedDoubleResult(value); + break; } - } /** diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index 533f21a92f..d806ef6842 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -145,6 +145,7 @@ public interface Cell { * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula * @since POI 3.15 beta 3 + * @deprecated will be removed in 4.2 * Will be renamed to <code>getCachedFormulaResultType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791. */ @Deprecated @@ -152,9 +153,9 @@ public interface Cell { CellType getCachedFormulaResultTypeEnum(); /** - * Set a numeric value for the cell + * Set a numeric value for the cell. * - * @param value the numeric value to set this cell to. For formulas we'll set the + * @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. */ diff --git a/src/java/org/apache/poi/ss/usermodel/CellBase.java b/src/java/org/apache/poi/ss/usermodel/CellBase.java index 46fa21f3f4..107f906668 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellBase.java +++ b/src/java/org/apache/poi/ss/usermodel/CellBase.java @@ -188,4 +188,29 @@ public abstract class CellBase implements Cell { tryToDeleteArrayFormula(null); } } + + /** + * {@inheritDoc} + */ + @Override + public final 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 { + setCellValueImpl(value); + } + } + + /** + * Implementation-specific way to set a numeric value. + * <code>value</code> is guaranteed to be a valid (non-NaN) double. + * The implementation is expected to adjust the cell type accordingly, so that after this call + * getCellType() or getCachedFormulaResultType() would return {@link CellType#NUMERIC}. + * @param value the new value to set + */ + protected abstract void setCellValueImpl(double value); } |