Author: centic
Date: Sun May  7 21:03:46 2017
New Revision: 1794260

URL: http://svn.apache.org/viewvc?rev=1794260&view=rev
Log:
Bug 60352: Text extraction: Don't include the text "null" for empty cells

Modified:
    
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java?rev=1794260&r1=1794259&r2=1794260&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java 
(original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java 
Sun May  7 21:03:46 2017
@@ -55,8 +55,8 @@ public class XSSFExcelExtractor extends
     private Locale locale;
     private XSSFWorkbook workbook;
     private boolean includeSheetNames = true;
-    private boolean formulasNotResults = false;
-    private boolean includeCellComments = false;
+    private boolean formulasNotResults;
+    private boolean includeCellComments;
     private boolean includeHeadersFooters = true;
     private boolean includeTextBoxes = true;
 
@@ -110,7 +110,7 @@ public class XSSFExcelExtractor extends
     }
     /**
      * Should text within textboxes be included? Default is true
-     * @param includeTextBoxes
+     * @param includeTextBoxes True if textboxes should be included, false if 
not.
      */
     public void setIncludeTextBoxes(boolean includeTextBoxes){
         this.includeTextBoxes = includeTextBoxes;
@@ -255,8 +255,10 @@ public class XSSFExcelExtractor extends
 
         // No supported styling applies to this cell
         String contents = ((XSSFCell)cell).getRawValue();
-        checkMaxTextSize(text, contents);
-        text.append( contents );
+        if (contents != null) {
+            checkMaxTextSize(text, contents);
+            text.append(contents);
+        }
     }
 
     private String extractHeaderFooter(HeaderFooter hf) {

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java?rev=1794260&r1=1794259&r2=1794260&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
 (original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
 Sun May  7 21:03:46 2017
@@ -45,7 +45,6 @@ public class TestXSSFExcelExtractor exte
 
        /**
         * Get text out of the simple file
-        * @throws IOException 
         */
        public void testGetSimpleText() throws IOException {
                // a very simple file
@@ -105,7 +104,7 @@ public class TestXSSFExcelExtractor exte
                
                extractor.close();
        }
-       
+
        public void testGetComplexText() throws IOException {
                // A fairly complex file
                XSSFExcelExtractor extractor = 
getExtractor("AverageTaxRates.xlsx");
@@ -114,10 +113,9 @@ public class TestXSSFExcelExtractor exte
                assertTrue(text.length() > 0);
                
                // Might not have all formatting it should do!
-               // TODO decide if we should really have the "null" in there
-               assertStartsWith(text, 
+               assertStartsWith(text,
                                                "Avgtxfull\n" +
-                                               "null\t(iii) AVERAGE TAX RATES 
ON ANNUAL"       
+                                               "\t(iii) AVERAGE TAX RATES ON 
ANNUAL"
                );
                
                extractor.close();
@@ -127,7 +125,6 @@ public class TestXSSFExcelExtractor exte
         * Test that we return pretty much the same as
         *  ExcelExtractor does, when we're both passed
         *  the same file, just saved as xls and xlsx
-        * @throws IOException 
         */
        public void testComparedToOLE2() throws IOException {
                // A fairly simple file - ooxml
@@ -156,7 +153,6 @@ public class TestXSSFExcelExtractor exte
        
        /**
         * From bug #45540
-        * @throws IOException 
         */
        public void testHeaderFooter() throws IOException {
                String[] files = new String[] {
@@ -176,7 +172,6 @@ public class TestXSSFExcelExtractor exte
 
        /**
         * From bug #45544
-        * @throws IOException 
         */
        public void testComments() throws IOException {
                XSSFExcelExtractor extractor = getExtractor("45544.xlsx");
@@ -220,7 +215,6 @@ public class TestXSSFExcelExtractor exte
        }
        /**
         * Simple test for text box text
-        * @throws IOException
         */
        public void testTextBoxes() throws IOException {
            XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx");



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to