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 edd0665b5..e9b75e536 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -293,14 +293,17 @@ public class XSSFExportToXml implements Comparator{ if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_STRING) { value = cell.getStringCellValue(); } else { - value += cell.getNumericCellValue(); + if (DateUtil.isCellDateFormatted(cell)) { + value = getFormattedDate(cell); + } else { + value += cell.getNumericCellValue(); + } } break; case XSSFCell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { - DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - value += sdf.format(cell.getDateCellValue()); + value = getFormattedDate(cell); } else { value += cell.getRawValue(); } @@ -321,7 +324,10 @@ public class XSSFExportToXml implements Comparator{ return elementName.matches(".*:.*")?elementName.split(":")[1]:elementName; } - + private String getFormattedDate(XSSFCell cell) { + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.format(cell.getDateCellValue()); + } private Node getNodeByXPath(String xpath,Node rootNode,Document doc,boolean createMultipleInstances) { String[] xpathTokens = xpath.split("/"); 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 3e279426c..9621b91eb 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -279,8 +279,8 @@ public final class TestXSSFExportToXML extends TestCase { assertNotNull(xmlData); assertFalse(xmlData.equals("")); - String date = xmlData.split("")[1].split("")[0].trim(); - assertEquals("2012-01-13", date); + assertEquals("2012-01-13", xmlData.split("")[1].split("")[0].trim()); + assertEquals("2012-02-16", xmlData.split("")[1].split("")[0].trim()); parseXML(xmlData); diff --git a/test-data/spreadsheet/55927.xlsx b/test-data/spreadsheet/55927.xlsx index e3d5a52cc..62fd046f5 100644 Binary files a/test-data/spreadsheet/55927.xlsx and b/test-data/spreadsheet/55927.xlsx differ