poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1736923 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/streaming/SXSSFCell.java java/org/apache/poi/xssf/usermodel/XSSFCell.java testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
Date Mon, 28 Mar 2016 20:20:29 GMT
Author: centic
Date: Mon Mar 28 20:20:29 2016
New Revision: 1736923

URL: http://svn.apache.org/viewvc?rev=1736923&view=rev
Log:
Bug 59199: Handle null date-values in a similar way as null-Strings

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java

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=1736923&r1=1736922&r2=1736923&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 Mon Mar 28 20:20:29
2016
@@ -21,6 +21,7 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Map;
 
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.formula.FormulaParseException;
@@ -206,6 +207,11 @@ public class SXSSFCell implements Cell {
      */
     @Override
     public void setCellValue(Date value) {
+        if(value == null) {
+            setCellType(Cell.CELL_TYPE_BLANK);
+            return;
+        }
+
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue(DateUtil.getExcelDate(value, date1904));
     }
@@ -228,6 +234,11 @@ public class SXSSFCell implements Cell {
      */
     @Override
     public void setCellValue(Calendar value) {
+        if(value == null) {
+            setCellType(Cell.CELL_TYPE_BLANK);
+            return;
+        }
+
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue( DateUtil.getExcelDate(value, date1904 ));
     }
@@ -549,7 +560,7 @@ public class SXSSFCell implements Cell {
      * the Workbook.</p>
      * 
      * <p>To change the style of a cell without affecting other cells that use the
same style,
-     * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
+     * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map<String,Object>)}</p>
      * 
      * @param style  reference contained in the workbook.
      * If the value is null then the style information is removed causing the cell to used
the default workbook style.

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=1736923&r1=1736922&r2=1736923&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 Mon Mar 28 20:20:29
2016
@@ -120,13 +120,13 @@ public final class XSSFCell implements C
     }
     
     /**
-     * Copy cell value, formula, and style, from srcCell per cell copy policy
+     * Copy cell value, formula and style, from srcCell per cell copy policy
      * If srcCell is null, clears the cell value and cell style per cell copy policy
      * 
      * This does not shift references in formulas. Use {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
to shift references in formulas.
      * 
-     * @param srcCell
-     * @param policy
+     * @param srcCell The cell to take value, formula and style from
+     * @param policy The policy for copying the information, see {@link CellCopyPolicy}
      * @throws IllegalArgumentException if copy cell style and srcCell is from a different
workbook
      */
     @Beta
@@ -619,7 +619,7 @@ public final class XSSFCell implements C
      * the XSSFWorkbook.</p>
      *
      * <p>To change the style of a cell without affecting other cells that use the
same style,
-     * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
+     * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, java.util.Map<String,
Object>)}</p>
      * 
      * @param style  reference contained in the workbook.
      * If the value is null then the style information is removed causing the cell to used
the default workbook style.
@@ -718,8 +718,7 @@ public final class XSSFCell implements C
      */
     @Override
     public Date getDateCellValue() {
-        int cellType = getCellType();
-        if (cellType == CELL_TYPE_BLANK) {
+        if (getCellType() == CELL_TYPE_BLANK) {
             return null;
         }
 
@@ -738,6 +737,11 @@ public final class XSSFCell implements C
      */
     @Override
     public void setCellValue(Date value) {
+        if(value == null) {
+            setCellType(Cell.CELL_TYPE_BLANK);
+            return;
+        }
+
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue(DateUtil.getExcelDate(value, date1904));
     }
@@ -760,6 +764,11 @@ public final class XSSFCell implements C
      */
     @Override
     public void setCellValue(Calendar value) {
+        if(value == null) {
+            setCellType(Cell.CELL_TYPE_BLANK);
+            return;
+        }
+
         boolean date1904 = getSheet().getWorkbook().isDate1904();
         setCellValue( DateUtil.getExcelDate(value, date1904 ));
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java?rev=1736923&r1=1736922&r2=1736923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java Mon Mar 28
20:20:29 2016
@@ -20,6 +20,8 @@ package org.apache.poi.ss.usermodel;
 import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
 
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.ss.ITestDataProvider;
@@ -55,4 +57,16 @@ public abstract class BaseTestXCell exte
         assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
         wb2.close();
     }
+
+    @Test
+    public void testSetNullValues() {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+
+        cell.setCellValue((Calendar)null);
+        cell.setCellValue((Date)null);
+        cell.setCellValue((String)null);
+        cell.setCellValue((RichTextString) null);
+        cell.setCellValue((String)null);
+    }
 }



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


Mime
View raw message