You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2014/07/30 18:10:56 UTC

svn commit: r1614696 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java test-data/spreadsheet/55927.xlsx

Author: nick
Date: Wed Jul 30 16:10:56 2014
New Revision: 1614696

URL: http://svn.apache.org/r1614696
Log:
Updated patch from Marc from #55927 - handle date formulas too

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
    poi/trunk/test-data/spreadsheet/55927.xlsx   (contents, props changed)

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java?rev=1614696&r1=1614695&r2=1614696&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java Wed Jul 30 16:10:56 2014
@@ -293,14 +293,17 @@ public class XSSFExportToXml implements 
            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 
         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("/");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java?rev=1614696&r1=1614695&r2=1614696&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java Wed Jul 30 16:10:56 2014
@@ -279,8 +279,8 @@ public final class TestXSSFExportToXML e
            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);
            

Modified: poi/trunk/test-data/spreadsheet/55927.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/55927.xlsx?rev=1614696&r1=1614695&r2=1614696&view=diff
==============================================================================
Binary files - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/55927.xlsx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Wed Jul 30 16:10:56 2014
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org