From d9df038f4a5e9c08c96845288f2c69b2843161ac Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 7 May 2017 21:03:46 +0000 Subject: [PATCH] Bug 60352: Text extraction: Don't include the text "null" for empty cells git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1794260 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/extractor/XSSFExcelExtractor.java | 12 +++++++----- .../poi/xssf/extractor/TestXSSFExcelExtractor.java | 12 +++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java index 192d60d71..f479ef3b4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java @@ -55,8 +55,8 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor 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 POIXMLTextExtractor } /** * 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 POIXMLTextExtractor // 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) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java index 3fc281808..f4450c010 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java @@ -45,7 +45,6 @@ public class TestXSSFExcelExtractor extends TestCase { /** * 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 extends TestCase { extractor.close(); } - + public void testGetComplexText() throws IOException { // A fairly complex file XSSFExcelExtractor extractor = getExtractor("AverageTaxRates.xlsx"); @@ -114,10 +113,9 @@ public class TestXSSFExcelExtractor extends TestCase { 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 extends TestCase { * 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 extends TestCase { /** * From bug #45540 - * @throws IOException */ public void testHeaderFooter() throws IOException { String[] files = new String[] { @@ -176,7 +172,6 @@ public class TestXSSFExcelExtractor extends TestCase { /** * From bug #45544 - * @throws IOException */ public void testComments() throws IOException { XSSFExcelExtractor extractor = getExtractor("45544.xlsx"); @@ -220,7 +215,6 @@ public class TestXSSFExcelExtractor extends TestCase { } /** * Simple test for text box text - * @throws IOException */ public void testTextBoxes() throws IOException { XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx");