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
This commit is contained in:
Dominik Stadler 2017-05-07 21:03:46 +00:00
parent 8313b17515
commit d9df038f4a
2 changed files with 10 additions and 14 deletions

View File

@ -55,8 +55,8 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor
private Locale locale; private Locale locale;
private XSSFWorkbook workbook; private XSSFWorkbook workbook;
private boolean includeSheetNames = true; private boolean includeSheetNames = true;
private boolean formulasNotResults = false; private boolean formulasNotResults;
private boolean includeCellComments = false; private boolean includeCellComments;
private boolean includeHeadersFooters = true; private boolean includeHeadersFooters = true;
private boolean includeTextBoxes = true; private boolean includeTextBoxes = true;
@ -110,7 +110,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor
} }
/** /**
* Should text within textboxes be included? Default is true * 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){ public void setIncludeTextBoxes(boolean includeTextBoxes){
this.includeTextBoxes = includeTextBoxes; this.includeTextBoxes = includeTextBoxes;
@ -255,8 +255,10 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor
// No supported styling applies to this cell // No supported styling applies to this cell
String contents = ((XSSFCell)cell).getRawValue(); String contents = ((XSSFCell)cell).getRawValue();
checkMaxTextSize(text, contents); if (contents != null) {
text.append( contents ); checkMaxTextSize(text, contents);
text.append(contents);
}
} }
private String extractHeaderFooter(HeaderFooter hf) { private String extractHeaderFooter(HeaderFooter hf) {

View File

@ -45,7 +45,6 @@ public class TestXSSFExcelExtractor extends TestCase {
/** /**
* Get text out of the simple file * Get text out of the simple file
* @throws IOException
*/ */
public void testGetSimpleText() throws IOException { public void testGetSimpleText() throws IOException {
// a very simple file // a very simple file
@ -114,10 +113,9 @@ public class TestXSSFExcelExtractor extends TestCase {
assertTrue(text.length() > 0); assertTrue(text.length() > 0);
// Might not have all formatting it should do! // 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" + "Avgtxfull\n" +
"null\t(iii) AVERAGE TAX RATES ON ANNUAL" "\t(iii) AVERAGE TAX RATES ON ANNUAL"
); );
extractor.close(); extractor.close();
@ -127,7 +125,6 @@ public class TestXSSFExcelExtractor extends TestCase {
* Test that we return pretty much the same as * Test that we return pretty much the same as
* ExcelExtractor does, when we're both passed * ExcelExtractor does, when we're both passed
* the same file, just saved as xls and xlsx * the same file, just saved as xls and xlsx
* @throws IOException
*/ */
public void testComparedToOLE2() throws IOException { public void testComparedToOLE2() throws IOException {
// A fairly simple file - ooxml // A fairly simple file - ooxml
@ -156,7 +153,6 @@ public class TestXSSFExcelExtractor extends TestCase {
/** /**
* From bug #45540 * From bug #45540
* @throws IOException
*/ */
public void testHeaderFooter() throws IOException { public void testHeaderFooter() throws IOException {
String[] files = new String[] { String[] files = new String[] {
@ -176,7 +172,6 @@ public class TestXSSFExcelExtractor extends TestCase {
/** /**
* From bug #45544 * From bug #45544
* @throws IOException
*/ */
public void testComments() throws IOException { public void testComments() throws IOException {
XSSFExcelExtractor extractor = getExtractor("45544.xlsx"); XSSFExcelExtractor extractor = getExtractor("45544.xlsx");
@ -220,7 +215,6 @@ public class TestXSSFExcelExtractor extends TestCase {
} }
/** /**
* Simple test for text box text * Simple test for text box text
* @throws IOException
*/ */
public void testTextBoxes() throws IOException { public void testTextBoxes() throws IOException {
XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx"); XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx");