You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ga...@apache.org on 2019/01/26 23:19:53 UTC
svn commit: r1852253 - in /poi/trunk/src:
java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/
ooxml/java/org/apache/poi/xssf/streaming/
ooxml/java/org/apache/poi/xssf/usermodel/
Author: gallon
Date: Sat Jan 26 23:19:53 2019
New Revision: 1852253
URL: http://svn.apache.org/viewvc?rev=1852253&view=rev
Log:
pulled *Cell.setCellValue(double) to the common base
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=1852253&r1=1852252&r2=1852253&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Sat Jan 26 23:19:53 2019
@@ -50,7 +50,6 @@ import org.apache.poi.ss.usermodel.Comme
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;
}
-
}
/**
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java?rev=1852253&r1=1852252&r2=1852253&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java Sat Jan 26 23:19:53 2019
@@ -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.
*/
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java?rev=1852253&r1=1852252&r2=1852253&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java Sat Jan 26 23:19:53 2019
@@ -188,4 +188,29 @@ public abstract class CellBase implement
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);
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1852253&r1=1852252&r2=1852253&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Sat Jan 26 23:19:53 2019
@@ -36,7 +36,6 @@ import org.apache.poi.ss.usermodel.Formu
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
-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.util.*;
@@ -159,27 +158,15 @@ public class SXSSFCell 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}
*/
@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)){
- setCellErrorValue(FormulaError.NUM.getCode());
+ public void setCellValueImpl(double value) {
+ ensureTypeOrFormulaType(CellType.NUMERIC);
+ if(_value.getType() == CellType.FORMULA) {
+ ((NumericFormulaValue) _value).setPreEvaluatedValue(value);
} else {
- ensureTypeOrFormulaType(CellType.NUMERIC);
- if(_value.getType()==CellType.FORMULA)
- ((NumericFormulaValue)_value).setPreEvaluatedValue(value);
- else
- ((NumericValue)_value).setValue(value);
+ ((NumericValue)_value).setValue(value);
}
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1852253&r1=1852252&r2=1852253&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sat Jan 26 23:19:53 2019
@@ -311,30 +311,13 @@ public final class XSSFCell extends Cell
}
}
-
/**
- * 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}
*/
@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.
- _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));
- }
+ public void setCellValueImpl(double value) {
+ _cell.setT(STCellType.N);
+ _cell.setV(String.valueOf(value));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org