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:59 UTC

svn commit: r1852254 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFCell.java java/org/apache/poi/ss/usermodel/CellBase.java ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java

Author: gallon
Date: Sat Jan 26 23:19:59 2019
New Revision: 1852254

URL: http://svn.apache.org/viewvc?rev=1852254&view=rev
Log:
pulled *Cell.setCellValue(Date) and setCellValue(Calendar) 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/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=1852254&r1=1852253&r2=1852254&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:59 2019
@@ -442,45 +442,21 @@ public class HSSFCell extends CellBase {
     }
 
     /**
-     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
-     * a date.
+     * {@inheritDoc}
      *
-     * @param value  the date 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.
+     * <p>In HSSF, only the number of days is stored. The fractional part is ignored.</p>
+     * @see HSSFDateUtil
+     * @see org.apache.poi.ss.usermodel.DateUtil
      */
-    public void setCellValue(Date value)
-    {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    protected void setCellValueImpl(Date value) {
         setCellValue(HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing()));
     }
 
     /**
-     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
-     * a date.
-     *
-     * This will set the cell value based on the Calendar's timezone. As Excel
-     * does not support timezones this means that both 20:00+03:00 and
-     * 20:00-03:00 will be reported as the same value (20:00) even that there
-     * are 6 hours difference between the two times. This difference can be
-     * preserved by using <code>setCellValue(value.getTime())</code> which will
-     * automatically shift the times to the default timezone.
-     *
-     * @param value  the date value to set this cell to.  For formulas we'll set the
-     *        precalculated value, for numerics we'll set its value. For othertypes we
-     *        will change the cell to a numeric cell and set its value.
+     * {@inheritDoc}
      */
-    public void setCellValue(Calendar value)
-    {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    @Override
+    protected void setCellValueImpl(Calendar value) {
         setCellValue( HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing()) );
     }
 

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=1852254&r1=1852253&r2=1852254&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:59 2019
@@ -23,6 +23,9 @@ import org.apache.poi.ss.util.CellRangeA
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.Removal;
 
+import java.util.Calendar;
+import java.util.Date;
+
 /**
  * Common implementation-independent logic shared by all implementations of {@link Cell}.
  * @author Vladislav "gallon" Galas gallon at apache dot org
@@ -213,4 +216,43 @@ public abstract class CellBase implement
      * @param value the new value to set
      */
     protected abstract void setCellValueImpl(double value);
+
+    @Override
+    public void setCellValue(Date value) {
+        if(value == null) {
+            setBlank();
+            return;
+        }
+        setCellValueImpl(value);
+    }
+
+    /**
+     * Implementation-specific way to set a date value.
+     * <code>value</code> is guaranteed to be non-null.
+     * 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 date to set
+     */
+    protected abstract void setCellValueImpl(Date value);
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void setCellValue(Calendar value) {
+        if(value == null) {
+            setBlank();
+            return;
+        }
+        setCellValueImpl(value);
+    }
+
+    /**
+     * Implementation-specific way to set a calendar value.
+     * <code>value</code> is guaranteed to be non-null.
+     * 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 calendar value to set
+     */
+    protected abstract void setCellValueImpl(Calendar 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=1852254&r1=1852253&r2=1852254&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:59 2019
@@ -171,54 +171,20 @@ public class SXSSFCell extends CellBase
     }
 
     /**
-     * Converts the supplied date to its equivalent Excel numeric value and sets
-     * that into the cell.
-     * <p>
-     * <b>Note</b> - There is actually no 'DATE' cell type in Excel. In many
-     * cases (when entering date values), Excel automatically adjusts the
-     * <i>cell style</i> to some date format, creating the illusion that the cell
-     * data type is now something besides {@link CellType#NUMERIC}.  POI
-     * does not attempt to replicate this behaviour.  To make a numeric cell
-     * display as a date, use {@link #setCellStyle(CellStyle)} etc.
-     *
-     * @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 numerics cell and set its value.
+     * {@inheritDoc}
      */
     @Override
-    public void setCellValue(Date value) {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    protected void setCellValueImpl(Date value) {
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue(DateUtil.getExcelDate(value, date1904));
     }
 
+
     /**
-     * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
-     * a date.
-     * <p>
-     * This will set the cell value based on the Calendar's timezone. As Excel
-     * does not support timezones this means that both 20:00+03:00 and
-     * 20:00-03:00 will be reported as the same value (20:00) even that there
-     * are 6 hours difference between the two times. This difference can be
-     * preserved by using <code>setCellValue(value.getTime())</code> which will
-     * automatically shift the times to the default timezone.
-     * </p>
-     *
-     * @param value  the date value to set this cell to.  For formulas we'll set the
-     *        precalculated value, for numerics we'll set its value. For othertypes we
-     *        will change the cell to a numeric cell and set its value.
+     * {@inheritDoc}
      */
     @Override
-    public void setCellValue(Calendar value) {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    protected void setCellValueImpl(Calendar value) {
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue( DateUtil.getExcelDate(value, date1904 ));
     }

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=1852254&r1=1852253&r2=1852254&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:59 2019
@@ -776,47 +776,19 @@ public final class XSSFCell extends Cell
     }
 
     /**
-     * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
-     * a date.
-     *
-     * @param value  the date 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(Date value) {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    protected void setCellValueImpl(Date value) {
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue(DateUtil.getExcelDate(value, date1904));
     }
 
     /**
-     * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
-     * a date.
-     * <p>
-     * This will set the cell value based on the Calendar's timezone. As Excel
-     * does not support timezones this means that both 20:00+03:00 and
-     * 20:00-03:00 will be reported as the same value (20:00) even that there
-     * are 6 hours difference between the two times. This difference can be
-     * preserved by using <code>setCellValue(value.getTime())</code> which will
-     * automatically shift the times to the default timezone.
-     * </p>
-     *
-     * @param value  the date value to set this cell to.  For formulas we'll set the
-     *        precalculated value, for numerics we'll set its value. For othertypes we
-     *        will change the cell to a numeric cell and set its value.
+     * {@inheritDoc}
      */
     @Override
-    public void setCellValue(Calendar value) {
-        if(value == null) {
-            setBlank();
-            return;
-        }
-
+    protected void setCellValueImpl(Calendar value) {
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue( DateUtil.getExcelDate(value, date1904 ));
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org