poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1610482 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java test-data/spreadsheet/56702.xlsx
Date Mon, 14 Jul 2014 18:53:39 GMT
Author: nick
Date: Mon Jul 14 18:53:39 2014
New Revision: 1610482

URL: http://svn.apache.org/r1610482
Log:
Fix for #56702 - If a cell is of type numeric but has an empty <v/> tag, return as 0

Added:
    poi/trunk/test-data/spreadsheet/56702.xlsx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

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=1610482&r1=1610481&r2=1610482&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 Jul 14 18:53:39
2014
@@ -206,8 +206,10 @@ public final class XSSFCell implements C
             case CELL_TYPE_FORMULA:
             case CELL_TYPE_NUMERIC:
                 if(_cell.isSetV()) {
+                   String v = _cell.getV();
+                   if (v.isEmpty()) return 0.0;
                    try {
-                      return Double.parseDouble(_cell.getV());
+                      return Double.parseDouble(v);
                    } catch(NumberFormatException e) {
                       throw typeMismatch(CELL_TYPE_NUMERIC, CELL_TYPE_STRING, false);
                    }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1610482&r1=1610481&r2=1610482&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Mon Jul
14 18:53:39 2014
@@ -1628,6 +1628,31 @@ public final class TestXSSFBugs extends 
         saveAndReloadReport(wb, xlsOutput);
     }
 
+    /**
+     * XSSFCell.typeMismatch on certain blank cells when formatting
+     *  with DataFormatter
+     */
+    @Test
+    public void bug56702() throws Exception {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56702.xlsx");
+        
+        Sheet sheet = wb.getSheetAt(0);
+
+        // Get wrong cell by row 8 & column 7
+        Cell cell = sheet.getRow(8).getCell(7);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        
+        // Check the value - will be zero as it is <c><v/></c>
+        assertEquals(0.0, cell.getNumericCellValue(), 0.001);
+        
+        // Try to format
+        DataFormatter formatter = new DataFormatter();
+        formatter.formatCellValue(cell);
+        
+        // Check the formatting
+        assertEquals("0", formatter.formatCellValue(cell));
+    }
+    
     private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
         // run some method on the font to verify if it is "disconnected" already
         //for(short i = 0;i < 256;i++)

Added: poi/trunk/test-data/spreadsheet/56702.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/56702.xlsx?rev=1610482&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/56702.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message