From 6dd3e805e7002a55bc67fc0a4db3e4124ed7389f Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 30 Jul 2014 16:10:56 +0000 Subject: [PATCH] Updated patch from Marc from #55927 - handle date formulas too git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614696 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/extractor/XSSFExportToXml.java | 14 ++++++++++---- .../xssf/extractor/TestXSSFExportToXML.java | 4 ++-- test-data/spreadsheet/55927.xlsx | Bin 11844 -> 10126 bytes 3 files changed, 12 insertions(+), 6 deletions(-) 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 edd0665b51..e9b75e5365 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 3e279426c3..9621b91eb4 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 e3d5a52cc0b44ff6edb2026614085de56f2930ba..62fd046f521d0ac685f225eb7f4682a99b02a8fe 100644 GIT binary patch delta 3504 zcmZ8k2{hDQ8y_>1W~>t;JK4uN7)92Q&`g%Mw^SHgj3vo3*2awT*|!;c$SzTKp@gwy z$u9enC1gz^iutC#^VNCZd(J)Qo_n9?-v4=?-}8HZ|JK_vSGi1#L0}F5Jpcj#0E7X2 z(ehrwbO3-{IhQC9k8*EOV0wLZ0$+4LV*)@bz~g0+*%nps;XGA@^KK_YRDi71G@xuV_tM+ej6Gx znSN})0bnmyNvTu>@3*RUu{je`y)i3!WsRH!tD~q3!pnGD`d6c?>i4iH0Q+D+rc8&* z%~0Mi>}N5s9L>hcW1%=9s&ZSEy?50pLfhzIun3go)g5Q*(9>LT-`7C#jJtyq`hmpQ z``1HGf%!t*jDjobMYb4>&t}cBP``dm$7=v-J$(l@i31{N? zs%DEIDIVX^|GFZs;0+|OAZA8uz=LX_20WrREqvLL4p)$n15j>)tm-D2SD+t-3R-*Y zz6sU#D*#JB@6_O*w+bIaubDZi!m)(s>IoW~hzAp&%4=CVXVo9eV;nIk?@tg&U=haM z#_jJiM^Sh6tnH@ACmz-(iXWvL)CvZI001f#L`q^~t?UGegBXwr0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