]> source.dussan.org Git - poi.git/commitdiff
Bug 53965: Fixed XmlValueOutOfRangeExceptio calling getDataValidations for custom...
authorYegor Kozlov <yegor@apache.org>
Wed, 10 Oct 2012 15:41:35 +0000 (15:41 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 10 Oct 2012 15:41:35 +0000 (15:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1396650 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java

index 1180c5cdfc9e69c4564da40082c6f9af08f87378..928e9c3172d9fae7a25fe711e5e91ced6bf6179b 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="fix">53965 - Fixed XmlValueOutOfRangeExceptio calling getDataValidations for custom validations with XSSFSheet </action>
           <action dev="poi-developers" type="fix">53974 - Avoid NPE when constructing HSSFWorbook on Google App Engine</action>
           <action dev="poi-developers" type="fix">53568 - Fixed null returned by XSSFPicture.getPictureData()</action>
           <action dev="poi-developers" type="fix">53950 - fixed setForceFormulaRecalculation to reset workbook-level "manual" flag</action>
index 3ef669877a7e5de27666c74af594e026489b9633..b0bd4e7835845c8ba3ed01767a4fd13007807a71 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOperator;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationType;
 
 /**
@@ -146,7 +147,10 @@ public class XSSFDataValidationHelper implements DataValidationHelper {
                }
                
                if (validationType!=ValidationType.ANY && validationType!=ValidationType.LIST) {
-                       newDataValidation.setOperator(XSSFDataValidation.operatorTypeMappings.get(constraint.getOperator()));                   
+            STDataValidationOperator.Enum op = XSSFDataValidation.operatorTypeMappings.get(constraint.getOperator());
+                       if(op != null) {
+                newDataValidation.setOperator(op);
+            }
                        if (constraint.getFormula1() != null) {
                                newDataValidation.setFormula1(constraint.getFormula1());
                        }
index a89c43bd83ec32c06ae9c3e0d13a4c1ffbe0e36c..35110797dfe8b3ddd3c6daff54f1c012d9007dc6 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
+import java.io.FileOutputStream;
 import java.math.BigDecimal;
 import java.util.List;
 
@@ -239,4 +240,25 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
                validation.createPromptBox("Prompt", "Enter some value");
                validation.setSuppressDropDownArrow(yesNo);
        }
+
+    public void test53965() throws Exception {
+
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        List<XSSFDataValidation> lst = sheet.getDataValidations();    //<-- works
+        assertEquals(0, lst.size());
+
+        //create the cell that will have the validation applied
+        sheet.createRow(0).createCell(0);
+
+        DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
+        DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("SUM($A$1:$A$1) <= 3500");
+        CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
+        DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
+        sheet.addValidationData(validation);
+
+        // this line caused XmlValueOutOfRangeException , see Bugzilla 3965
+        lst = sheet.getDataValidations();
+        assertEquals(1, lst.size());
+    }
 }