poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1563470 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java test-data/spreadsheet/56011.xlsx
Date Sat, 01 Feb 2014 20:54:10 GMT
Author: centic
Date: Sat Feb  1 20:54:09 2014
New Revision: 1563470

URL: http://svn.apache.org/r1563470
Log:
Bug 56011: Use default style if the cell style attribute is not present

Added:
    poi/trunk/test-data/spreadsheet/56011.xlsx
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java?rev=1563470&r1=1563469&r2=1563470&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java Sat
Feb  1 20:54:09 2014
@@ -132,6 +132,7 @@ public class XSSFSheetXMLHandler extends
       return false;
    }
    
+   @Override
    public void startElement(String uri, String localName, String name,
                             Attributes attributes) throws SAXException {
 
@@ -207,18 +208,26 @@ public class XSSFSheetXMLHandler extends
                nextDataType = xssfDataType.SST_STRING;
            else if ("str".equals(cellType))
                nextDataType = xssfDataType.FORMULA;
-           else if (cellStyleStr != null) {
-              // Number, but almost certainly with a special style or format
-               int styleIndex = Integer.parseInt(cellStyleStr);
-               XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
-               this.formatIndex = style.getDataFormat();
-               this.formatString = style.getDataFormatString();
-               if (this.formatString == null)
-                   this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
+           else {
+               // Number, but almost certainly with a special style or format
+               XSSFCellStyle style = null;
+               if (cellStyleStr != null) {
+                   int styleIndex = Integer.parseInt(cellStyleStr);
+                   style = stylesTable.getStyleAt(styleIndex);
+               } else if (stylesTable.getNumCellStyles() > 0) {
+                   style = stylesTable.getStyleAt(0);
+               }
+               if (style != null) {
+                   this.formatIndex = style.getDataFormat();
+                   this.formatString = style.getDataFormatString();
+                   if (this.formatString == null)
+                       this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
+               }
            }
        }
    }
 
+   @Override
    public void endElement(String uri, String localName, String name)
            throws SAXException {
        String thisStr = null;
@@ -316,6 +325,7 @@ public class XSSFSheetXMLHandler extends
     * Captures characters only if a suitable element is open.
     * Originally was just "v"; extended for inlineStr also.
     */
+   @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        if (vIsOpen) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java?rev=1563470&r1=1563469&r2=1563470&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
Sat Feb  1 20:54:09 2014
@@ -17,7 +17,6 @@
 
 package org.apache.poi.xssf.extractor;
 
-import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -26,11 +25,7 @@ import junit.framework.TestCase;
 import org.apache.poi.POITextExtractor;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.extractor.ExcelExtractor;
-import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.apache.poi.xssf.usermodel.XSSFShape;
-import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
 
 /**
  * Tests for {@link XSSFEventBasedExcelExtractor}
@@ -187,4 +182,31 @@ public class TestXSSFEventBasedExcelExtr
 	    assertTrue(text.indexOf("Line 3") > -1);
 
     }
+
+    /**
+     * Test that we return the same output for unstyled numbers as the
+     * non-event-based XSSFExcelExtractor.
+     */
+    public void testUnstyledNumbersComparedToNonEventBasedExtractor()
+            throws Exception {
+
+        String expectedOutput = "Sheet1\n99.99\n";
+
+        XSSFExcelExtractor extractor = new XSSFExcelExtractor(
+                XSSFTestDataSamples.openSampleWorkbook("56011.xlsx"));
+        try {
+            assertEquals(expectedOutput, extractor.getText().replace(",", "."));
+        } finally {
+            extractor.close();
+        }
+
+        XSSFEventBasedExcelExtractor fixture =
+                new XSSFEventBasedExcelExtractor(
+                        XSSFTestDataSamples.openSamplePackage("56011.xlsx"));
+        try {
+            assertEquals(expectedOutput, fixture.getText().replace(",", "."));
+        } finally {
+            fixture.close();
+        }
+    }
 }

Added: poi/trunk/test-data/spreadsheet/56011.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/56011.xlsx?rev=1563470&view=auto
==============================================================================
Files poi/trunk/test-data/spreadsheet/56011.xlsx (added) and poi/trunk/test-data/spreadsheet/56011.xlsx
Sat Feb  1 20:54:09 2014 differ



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


Mime
View raw message