From d7028dcf09b672be3751521c5ec8d07af7e9c65f Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 3 Feb 2014 19:46:41 +0000 Subject: [PATCH] Bug 55926: Handle numeric formula values when exporting to XML git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1564028 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/extractor/XSSFExportToXml.java | 11 ++++++- .../xssf/extractor/TestXSSFExportToXML.java | 31 ++++++++++++++++++ test-data/spreadsheet/55926.xlsx | Bin 0 -> 12650 bytes 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/55926.xlsx diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 807a58418..49b095ede 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -43,6 +43,7 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFMap; @@ -283,7 +284,14 @@ public class XSSFExportToXml implements Comparator{ case XSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case XSSFCell.CELL_TYPE_BOOLEAN: value += cell.getBooleanCellValue(); break; case XSSFCell.CELL_TYPE_ERROR: value = cell.getErrorCellString(); break; - case XSSFCell.CELL_TYPE_FORMULA: value = cell.getStringCellValue(); break; + case XSSFCell.CELL_TYPE_FORMULA: + if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_STRING) { + value = cell.getStringCellValue(); + } else { + value += cell.getNumericCellValue(); + } + break; + case XSSFCell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -292,6 +300,7 @@ public class XSSFExportToXml implements Comparator{ value += cell.getRawValue(); } break; + default: ; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 6bcb71943..fbbf1e0eb 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -241,4 +241,35 @@ public final class TestXSSFExportToXML extends TestCase { assertEquals("2012-01-13", date); } } + + public void testFormulaCells_Bugzilla_55926() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55926.xlsx"); + + for (POIXMLDocumentPart p : wb.getRelations()) { + + if (!(p instanceof MapInfo)) { + continue; + } + MapInfo mapInfo = (MapInfo) p; + + XSSFMap map = mapInfo.getXSSFMapById(1); + + assertNotNull("XSSFMap is null", map); + + XSSFExportToXml exporter = new XSSFExportToXml(map); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + exporter.exportToXML(os, true); + String xmlData = os.toString("UTF-8"); + + assertNotNull(xmlData); + assertFalse(xmlData.equals("")); + + String a = xmlData.split("")[1].split("")[0].trim(); + String doubleValue = a.split("")[1].split("")[0].trim(); + String stringValue = a.split("")[1].split("")[0].trim(); + + assertEquals("Hello World", stringValue); + assertEquals("5.1", doubleValue); + } + } } diff --git a/test-data/spreadsheet/55926.xlsx b/test-data/spreadsheet/55926.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..23907c1d5817b661f3e6cb101131818879a90b3d GIT binary patch literal 12650 zcmeHtWmH_*wr=6>?(QzZgOd;ncXxMpNN|En;SwxZkl=2?Lh#`35}e?{UL}3*NjKg1 zjyK+q_vfBHMpcc?+HmnK6213FuL}i8w;3y9{$q z#^)MbaTfOvA(LHLo_k7>6rn*xsik-?dk+H}G-PO}BaLgDXO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