summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-07-30 16:10:56 +0000
committerNick Burch <nick@apache.org>2014-07-30 16:10:56 +0000
commit6dd3e805e7002a55bc67fc0a4db3e4124ed7389f (patch)
treea006a4bb615fa32cd0b267e03a0c3e6d0c44f9b7
parent8eb7e4a7f43336bc916393b65b800b53594e43b5 (diff)
downloadpoi-6dd3e805e7002a55bc67fc0a4db3e4124ed7389f.tar.gz
poi-6dd3e805e7002a55bc67fc0a4db3e4124ed7389f.zip
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
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java14
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java4
-rw-r--r--test-data/spreadsheet/55927.xlsxbin11844 -> 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<String>{
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<String>{
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("<DATE>")[1].split("</DATE>")[0].trim();
- assertEquals("2012-01-13", date);
+ assertEquals("2012-01-13", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
+ assertEquals("2012-02-16", xmlData.split("<FORMULA_DATE>")[1].split("</FORMULA_DATE>")[0].trim());
parseXML(xmlData);
diff --git a/test-data/spreadsheet/55927.xlsx b/test-data/spreadsheet/55927.xlsx
index e3d5a52cc0..62fd046f52 100644
--- a/test-data/spreadsheet/55927.xlsx
+++ b/test-data/spreadsheet/55927.xlsx
Binary files differ