Skip to content

Commit

Permalink
[bug-67785] make XSSFExcelExtractor output more like that from XSSFEv…
Browse files Browse the repository at this point in the history
…entBasedExcelExtractor

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1913080 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Oct 18, 2023
1 parent e80ae0b commit 9a8ea4a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class XSSFExcelExtractor

private Locale locale;
private final XSSFWorkbook workbook;
private final DataFormatter dataFormatter;
private boolean includeSheetNames = true;
private boolean formulasNotResults;
private boolean includeCellComments;
Expand All @@ -67,6 +68,8 @@ public XSSFExcelExtractor(OPCPackage container) throws XmlException, OpenXML4JEx
}
public XSSFExcelExtractor(XSSFWorkbook workbook) {
this.workbook = workbook;
this.dataFormatter = new DataFormatter();
this.dataFormatter.setUseCachedValuesForFormulaCells(true);
}

/**
Expand Down Expand Up @@ -243,8 +246,12 @@ private void handleNonStringCell(StringBuilder text, Cell cell, DataFormatter fo
}

// No supported styling applies to this cell
String contents = ((XSSFCell)cell).getRawValue();
String contents = dataFormatter.formatCellValue(cell);
if (contents != null) {
if (type == CellType.ERROR) {
// to match what XSSFEventBasedExcelExtractor does
contents = "ERROR:" + contents;
}
checkMaxTextSize(text, contents);
text.append(contents);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ void testPhoneticRuns() throws Exception {
}
}

@Test
void test67784() throws Exception {
try (XSSFExcelExtractor extractor = getExtractor("bug67784.xlsx")) {
String text = extractor.getText().replace("\r", "");
String[] lines = text.split("\n");
assertEquals("FALSE", lines[2]);
assertEquals("TRUE", lines[3]);
assertEquals("ERROR:#DIV/0!", lines[4]);
}
}

@Test
void test67784Formulas() throws Exception {
try (XSSFExcelExtractor extractor = getExtractor("bug67784.xlsx")) {
Expand Down

0 comments on commit 9a8ea4a

Please sign in to comment.