poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1564028 - 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/55926.xlsx
Date Mon, 03 Feb 2014 19:46:42 GMT
Author: centic
Date: Mon Feb  3 19:46:41 2014
New Revision: 1564028

URL: http://svn.apache.org/r1564028
Log:
Bug 55926: Handle numeric formula values when exporting to XML

Added:
    poi/trunk/test-data/spreadsheet/55926.xlsx
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

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=1564028&r1=1564027&r2=1564028&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 Mon Feb  3
19:46:41 2014
@@ -43,6 +43,7 @@ import javax.xml.validation.SchemaFactor
 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 
         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 
                  value += cell.getRawValue();
               }
             break;
+
         default: ;
 
         }

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=1564028&r1=1564027&r2=1564028&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 Mon
Feb  3 19:46:41 2014
@@ -241,4 +241,35 @@ public final class TestXSSFExportToXML e
            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("<A>")[1].split("</A>")[0].trim();
+           String doubleValue = a.split("<DOUBLE>")[1].split("</DOUBLE>")[0].trim();
+           String stringValue = a.split("<STRING>")[1].split("</STRING>")[0].trim();
+           
+           assertEquals("Hello World", stringValue);
+           assertEquals("5.1", doubleValue);
+       }
+   }
 }

Added: poi/trunk/test-data/spreadsheet/55926.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/55926.xlsx?rev=1564028&view=auto
==============================================================================
Files poi/trunk/test-data/spreadsheet/55926.xlsx (added) and poi/trunk/test-data/spreadsheet/55926.xlsx
Mon Feb  3 19:46:41 2014 differ



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


Mime
View raw message