Added: poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterData.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterData.java?rev=1782894&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterData.java 
(added)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterData.java Mon 
Feb 13 22:51:30 2017
@@ -0,0 +1,57 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * These values are needed by various conditional formatting evaluation filter 
types
+ */
+public interface ConditionFilterData {
+
+    /**
+     * @return true if the flag is missing or set to true
+     */
+    boolean getAboveAverage();
+    
+    /**
+     * @return true if the flag is set
+     */
+    boolean getBottom();
+    
+    /**
+     * @return true if the flag is set
+     */
+    boolean getEqualAverage();
+
+    /**
+     * @return true if the flag is set
+     */
+    boolean getPercent();
+
+    /**
+     * @return value, or 0 if not used/defined
+     */
+    long getRank();
+
+    /**
+     * @return value, or 0 if not used/defined
+     */
+    int getStdDev();
+    
+}

Propchange: 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterType.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterType.java?rev=1782894&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterType.java 
(added)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterType.java Mon 
Feb 13 22:51:30 2017
@@ -0,0 +1,46 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Used primarily for XSSF conditions, which defines a multitude of additional 
"filter" types
+ * for conditional formatting.  HSSF rules will always be null (not a filter 
type) or #FILTER.
+ * XSSF conditions will be null (not a filter type) or any value other than 
#FILTER.
+ * <p/>
+ * Instance names match the constants from <code>STCfType</code> for 
convenience.
+ */
+public enum ConditionFilterType {
+    /** This is the only value valid for HSSF rules */
+    FILTER,
+    TOP_10,
+    UNIQUE_VALUES,
+    DUPLICATE_VALUES,
+    CONTAINS_TEXT,
+    NOT_CONTAINS_TEXT,
+    BEGINS_WITH,
+    ENDS_WITH,
+    CONTAINS_BLANKS,
+    NOT_CONTAINS_BLANKS,
+    CONTAINS_ERRORS,
+    NOT_CONTAINS_ERRORS,
+    TIME_PERIOD,
+    ABOVE_AVERAGE,
+    ;
+}

Propchange: 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionFilterType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java?rev=1782894&r1=1782893&r2=1782894&view=diff
==============================================================================
--- 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java 
(original)
+++ 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java 
Mon Feb 13 22:51:30 2017
@@ -83,6 +83,32 @@ public interface ConditionalFormattingRu
      * @return the type of condition
      */
     ConditionType getConditionType();
+    
+    /**
+     * This is null if 
+     * <p/>
+     * <code>{@link #getConditionType()} != {@link ConditionType#FILTER}</code>
+     * <p/>
+     * This is always {@link ConditionFilterType#FILTER} for HSSF rules of 
type {@link ConditionType#FILTER}.
+     * <p/>
+     * For XSSF filter rules, this will indicate the specific type of filter.
+     * 
+     * @return filter type for filter rules, or null if not a filter rule.
+     */
+    ConditionFilterType getConditionFilterType();
+    
+    /**
+     * This is null if 
+     * <p/>
+     * <code>{@link #getConditionFilterType()} == null</code>
+     * <p/>
+     * This means it is always null for HSSF, which does not define the 
extended condition types.
+     * <p/>
+     * This object contains the additional configuration information for XSSF 
filter conditions.
+     * 
+     * @return
+     */
+    public ConditionFilterData getFilterConfiguration();
 
     /**
      * The comparison function used when the type of conditional formatting is 
set to
@@ -119,4 +145,25 @@ public interface ConditionalFormattingRu
      * @return  the second formula
      */
     String getFormula2();
+
+    /**
+     * HSSF just returns 0, XSSF uses the value stored in the model if 
present, 
+     * otherwise uses 0.
+     * <p/>
+     * If priority is 0, just use definition order, as that's how HSSF rules 
are evaluated.
+     * <p/>
+     * If a rule is created but not yet added to a sheet, this value may not 
be valid.
+
+     * @return rule priority
+     */
+    int getPriority();
+    
+    /**
+     * Always true for HSSF rules, optional flag for XSSF rules.
+     * See Excel help for more.
+     * 
+     * @return true if conditional formatting rule processing stops when this 
one is true, false if not
+     * @see <a 
href="https://support.office.com/en-us/article/Manage-conditional-formatting-rule-precedence-063cde21-516e-45ca-83f5-8e8126076249";>Microsoft
 Excel help</a>
+     */
+    boolean getStopIfTrue();
 }

Added: 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java.svntmp
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java.svntmp?rev=1782894&view=auto
==============================================================================
--- 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java.svntmp
 (added)
+++ 
poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java.svntmp
 Mon Feb 13 22:51:30 2017
@@ -0,0 +1,169 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Represents a description of a conditional formatting rule
+ */
+public interface ConditionalFormattingRule {
+    /**
+     * Create a new border formatting structure if it does not exist,
+     * otherwise just return existing object.
+     *
+     * @return - border formatting object, never returns <code>null</code>.
+     */
+    BorderFormatting createBorderFormatting();
+
+    /**
+     * @return - border formatting object  if defined,  <code>null</code> 
otherwise
+     */
+    BorderFormatting getBorderFormatting();
+
+    /**
+     * Create a new font formatting structure if it does not exist,
+     * otherwise just return existing object.
+     *
+     * @return - font formatting object, never returns <code>null</code>.
+     */
+    FontFormatting createFontFormatting();
+
+    /**
+     * @return - font formatting object  if defined,  <code>null</code> 
otherwise
+     */
+    FontFormatting getFontFormatting();
+
+    /**
+     * Create a new pattern formatting structure if it does not exist,
+     * otherwise just return existing object.
+     *
+     * @return - pattern formatting object, never returns <code>null</code>.
+     */
+    PatternFormatting createPatternFormatting();
+
+    /**
+     * @return - pattern formatting object if defined, <code>null</code> 
otherwise
+     */
+    PatternFormatting getPatternFormatting();
+
+    /**
+     * @return - databar / data-bar formatting object if defined, 
<code>null</code> otherwise
+     */
+    DataBarFormatting getDataBarFormatting();
+    
+    /**
+     * @return - icon / multi-state formatting object if defined, 
<code>null</code> otherwise
+     */
+    IconMultiStateFormatting getMultiStateFormatting();
+    
+    /**
+     * @return color scale / color grate formatting object if defined, 
<code>null</code> otherwise
+     */
+    ColorScaleFormatting getColorScaleFormatting();
+    
+    /**
+     * Type of conditional formatting rule.
+     *
+     * @return the type of condition
+     */
+    ConditionType getConditionType();
+    
+    /**
+     * This is null if 
+     * <p/>
+     * <code>{@link #getConditionType()} != {@link ConditionType#FILTER}</code>
+     * <p/>
+     * This is always {@link ConditionFilterType#FILTER} for HSSF rules of 
type {@link ConditionType#FILTER}.
+     * <p/>
+     * For XSSF filter rules, this will indicate the specific type of filter.
+     * 
+     * @return filter type for filter rules, or null if not a filter rule.
+     */
+    ConditionFilterType getConditionFilterType();
+    
+    /**
+     * This is null if 
+     * <p/>
+     * <code>{@link #getConditionFilterType()} == null</code>
+     * <p/>
+     * This means it is always null for HSSF, which does not define the 
extended condition types.
+     * <p/>
+     * This object contains the additional configuration information for XSSF 
filter conditions.
+     * 
+     * @return
+     */
+    public ConditionFilterData getFilterConfiguration();
+
+    /**
+     * The comparison function used when the type of conditional formatting is 
set to
+     * {@link ConditionType#CELL_VALUE_IS}
+     * <p>
+     *     MUST be a constant from {@link ComparisonOperator}
+     * </p>
+     *
+     * @return the conditional format operator
+     */
+    byte getComparisonOperation();
+
+    /**
+     * The formula used to evaluate the first operand for the conditional 
formatting rule.
+     * <p>
+     * If the condition type is {@link ConditionType#CELL_VALUE_IS},
+     * this field is the first operand of the comparison.
+     * If type is {@link ConditionType#FORMULA}, this formula is used
+     * to determine if the conditional formatting is applied.
+     * </p>
+     * <p>
+     * If comparison type is {@link ConditionType#FORMULA} the formula MUST be 
a Boolean function
+     * </p>
+     *
+     * @return  the first formula
+     */
+    String getFormula1();
+
+    /**
+     * The formula used to evaluate the second operand of the comparison when
+     * comparison type is  {@link ConditionType#CELL_VALUE_IS} and operator
+     * is either {@link ComparisonOperator#BETWEEN} or {@link 
ComparisonOperator#NOT_BETWEEN}
+     *
+     * @return  the second formula
+     */
+    String getFormula2();
+
+    /**
+     * HSSF just returns 0, XSSF uses the value stored in the model if 
present, 
+     * otherwise uses 0.
+     * <p/>
+     * If priority is 0, just use definition order, as that's how HSSF rules 
are evaluated.
+     * <p/>
+     * If a rule is created but not yet added to a sheet, this value may not 
be valid.
+
+     * @return rule priority
+     */
+    int getPriority();
+    
+    /**
+     * Always true for HSSF rules, optional flag for XSSF rules.
+     * See Excel help for more.
+     * 
+     * @return true if conditional formatting rule processing stops when this 
one is true, false if not
+     * @see <a 
href="https://support.office.com/en-us/article/Manage-conditional-formatting-rule-precedence-063cde21-516e-45ca-83f5-8e8126076249";>Microsoft
 Excel help</a>
+     */
+    boolean getStopIfTrue();
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java?rev=1782894&r1=1782893&r2=1782894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java Mon Feb 
13 22:51:30 2017
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.util;
 
 import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.usermodel.Cell;
 
 
 /**
@@ -125,6 +126,34 @@ public abstract class CellRangeAddressBa
                                _firstCol <= colInd && colInd <= _lastCol; 
//containsColumn
        }
        
+    /**
+     * Determines if the given {@link CellReference} lies within the bounds 
+     * of this range.  
+     * <p/>NOTE: It is up to the caller to ensure the reference is 
+     * for the correct sheet, since this instance doesn't have a sheet 
reference.
+     *
+     * @param ref the CellReference to check
+     * @return True if the reference lies within the bounds, false otherwise.
+     * @see #intersects(CellRangeAddressBase) for checking if two ranges 
overlap
+     */
+       public boolean isInRange(CellReference ref) {
+           return isInRange(ref.getRow(), ref.getCol());
+       }
+       
+       /**
+        * Determines if the given {@link Cell} lies within the bounds 
+        * of this range.  
+        * <p/>NOTE: It is up to the caller to ensure the reference is 
+        * for the correct sheet, since this instance doesn't have a sheet 
reference.
+        *
+        * @param cell the Cell to check
+        * @return True if the cell lies within the bounds, false otherwise.
+        * @see #intersects(CellRangeAddressBase) for checking if two ranges 
overlap
+        */
+       public boolean isInRange(Cell cell) {
+           return isInRange(cell.getRowIndex(), cell.getColumnIndex());
+       }
+       
        /**
         * Check if the row is in the specified cell range
         *

Modified: poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java?rev=1782894&r1=1782893&r2=1782894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java Mon Feb 13 
22:51:30 2017
@@ -352,6 +352,29 @@ public class SheetUtil {
     }
 
     /**
+     * Return the cell, without taking account of merged regions.
+     * <p/>
+     * Use {@link #getCellWithMerges(Sheet, int, int)} if you want the top left
+     * cell from merged regions instead when the reference is a merged cell.
+     * <p/>
+     * Use this where you want to know if the given cell is explicitly defined
+     * or not.
+     *
+     * @param sheet
+     * @param rowIx
+     * @param colIx
+     * @return cell at the given location, or null if not defined
+     * @throws NullPointerException if sheet is null
+     */
+    public static Cell getCell(Sheet sheet, int rowIx, int colIx) {
+        Row r = sheet.getRow(rowIx);
+        if (r != null) {
+            return r.getCell(colIx);
+        }
+        return null;
+    }
+
+    /**
      * Return the cell, taking account of merged regions. Allows you to find 
the
      *  cell who's contents are shown in a given position in the sheet.
      * 
@@ -361,22 +384,22 @@ public class SheetUtil {
      *  then will return the cell itself.
      * <p>If there is no cell defined at the given co-ordinates, will return
      *  null.
+     *  
+     * @param sheet
+     * @param rowIx
+     * @param colIx
+     * @return cell at the given location, its base merged cell, or null if 
not defined
+     * @throws NullPointerException if sheet is null
      */
     public static Cell getCellWithMerges(Sheet sheet, int rowIx, int colIx) {
-        Row r = sheet.getRow(rowIx);
-        if (r != null) {
-            Cell c = r.getCell(colIx);
-            if (c != null) {
-                // Normal, non-merged cell
-                return c;
-            }
-        }
+        final Cell c = getCell(sheet, rowIx, colIx);
+        if (c != null) return c;
         
         for (CellRangeAddress mergedRegion : sheet.getMergedRegions()) {
             if (mergedRegion.isInRange(rowIx, colIx)) {
                 // The cell wanted is in this merged range
                 // Return the primary (top-left) cell for the range
-                r = sheet.getRow(mergedRegion.getFirstRow());
+                Row r = sheet.getRow(mergedRegion.getFirstRow());
                 if (r != null) {
                     return r.getCell(mergedRegion.getFirstColumn());
                 }

Added: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionFilterData.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionFilterData.java?rev=1782894&view=auto
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionFilterData.java
 (added)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionFilterData.java
 Mon Feb 13 22:51:30 2017
@@ -0,0 +1,57 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.ConditionFilterData;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
+
+public class XSSFConditionFilterData implements ConditionFilterData {
+
+    private final CTCfRule _cfRule;
+    
+    /*package*/ XSSFConditionFilterData(CTCfRule cfRule) {
+        _cfRule = cfRule;
+    }
+
+    public boolean getAboveAverage() {
+        return _cfRule.getAboveAverage();
+    }
+
+    public boolean getBottom() {
+        return _cfRule.getBottom();
+    }
+
+    public boolean getEqualAverage() {
+        return _cfRule.getEqualAverage();
+    }
+
+    public boolean getPercent() {
+        return _cfRule.getPercent();
+    }
+
+    public long getRank() {
+        return _cfRule.getRank();
+    }
+
+    public int getStdDev() {
+        return _cfRule.getStdDev();
+    }
+
+}

Propchange: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionFilterData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java?rev=1782894&r1=1782893&r2=1782894&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
 (original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
 Mon Feb 13 22:51:30 2017
@@ -30,13 +30,14 @@ import org.apache.poi.xssf.model.StylesT
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 /**
- * XSSF suport for Conditional Formatting rules
+ * XSSF support for Conditional Formatting rules
  */
 public class XSSFConditionalFormattingRule implements 
ConditionalFormattingRule {
     private final CTCfRule _cfRule;
     private XSSFSheet _sh;
     
     private static Map<STCfType.Enum, ConditionType> typeLookup = new 
HashMap<STCfType.Enum, ConditionType>();
+    private static Map<STCfType.Enum, ConditionFilterType> filterTypeLookup = 
new HashMap<STCfType.Enum, ConditionFilterType>();
     static {
         typeLookup.put(STCfType.CELL_IS, ConditionType.CELL_VALUE_IS);
         typeLookup.put(STCfType.EXPRESSION, ConditionType.FORMULA);
@@ -58,8 +59,27 @@ public class XSSFConditionalFormattingRu
         typeLookup.put(STCfType.NOT_CONTAINS_ERRORS, ConditionType.FILTER);
         typeLookup.put(STCfType.TIME_PERIOD, ConditionType.FILTER);
         typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);
+        
+        filterTypeLookup.put(STCfType.TOP_10, ConditionFilterType.TOP_10);
+        filterTypeLookup.put(STCfType.UNIQUE_VALUES, 
ConditionFilterType.UNIQUE_VALUES);
+        filterTypeLookup.put(STCfType.DUPLICATE_VALUES, 
ConditionFilterType.DUPLICATE_VALUES);
+        filterTypeLookup.put(STCfType.CONTAINS_TEXT, 
ConditionFilterType.CONTAINS_TEXT);
+        filterTypeLookup.put(STCfType.NOT_CONTAINS_TEXT, 
ConditionFilterType.NOT_CONTAINS_TEXT);
+        filterTypeLookup.put(STCfType.BEGINS_WITH, 
ConditionFilterType.BEGINS_WITH);
+        filterTypeLookup.put(STCfType.ENDS_WITH, 
ConditionFilterType.ENDS_WITH);
+        filterTypeLookup.put(STCfType.CONTAINS_BLANKS, 
ConditionFilterType.CONTAINS_BLANKS);
+        filterTypeLookup.put(STCfType.NOT_CONTAINS_BLANKS, 
ConditionFilterType.NOT_CONTAINS_BLANKS);
+        filterTypeLookup.put(STCfType.CONTAINS_ERRORS, 
ConditionFilterType.CONTAINS_ERRORS);
+        filterTypeLookup.put(STCfType.NOT_CONTAINS_ERRORS, 
ConditionFilterType.NOT_CONTAINS_ERRORS);
+        filterTypeLookup.put(STCfType.TIME_PERIOD, 
ConditionFilterType.TIME_PERIOD);
+        filterTypeLookup.put(STCfType.ABOVE_AVERAGE, 
ConditionFilterType.ABOVE_AVERAGE);
+
     }
     
+    /**
+     * NOTE: does not set priority, so this assumes the rule will not be added 
to the sheet yet
+     * @param sh
+     */
     /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){
         _cfRule = CTCfRule.Factory.newInstance();
         _sh = sh;
@@ -89,6 +109,16 @@ public class XSSFConditionalFormattingRu
         return dxf;
     }
 
+    public int getPriority() {
+        final int priority = _cfRule.getPriority();
+        // priorities start at 1, if it is less, it is undefined, use 
definition order in caller
+        return priority >=1 ? priority : 0;
+    }
+    
+    public boolean getStopIfTrue() {
+        return _cfRule.getStopIfTrue();
+    }
+    
     /**
      * Create a new border formatting structure if it does not exist,
      * otherwise just return existing object.
@@ -304,6 +334,18 @@ public class XSSFConditionalFormattingRu
     }
 
     /**
+     * Will return null if {@link #getConditionType()} != {@link 
ConditionType#FILTER}
+     * @see 
org.apache.poi.ss.usermodel.ConditionalFormattingRule#getConditionFilterType()
+     */
+    public ConditionFilterType getConditionFilterType() {
+        return filterTypeLookup.get(_cfRule.getType());
+    }
+    
+    public ConditionFilterData getFilterConfiguration() {
+        return new XSSFConditionFilterData(_cfRule);
+    }
+    
+    /**
      * The comparison function used when the type of conditional formatting is 
set to
      * {@link ConditionType#CELL_VALUE_IS}
      * <p>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1782894&r1=1782893&r2=1782894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon 
Feb 13 22:51:30 2017
@@ -3869,7 +3869,7 @@ public class XSSFSheet extends POIXMLDoc
             throw new IllegalArgumentException("Specified cell does not belong 
to this sheet.");
         }
         for (CellRangeAddress range : arrayFormulas) {
-            if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) {
+            if (range.isInRange(cell)) {
                 arrayFormulas.remove(range);
                 CellRange<XSSFCell> cr = getCellRange(range);
                 for (XSSFCell c : cr) {

Added: 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/ConditionalFormattingEvalTest.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/ConditionalFormattingEvalTest.java?rev=1782894&view=auto
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/ConditionalFormattingEvalTest.java
 (added)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/ConditionalFormattingEvalTest.java
 Mon Feb 13 22:51:30 2017
@@ -0,0 +1,118 @@
+package org.apache.poi.ss.usermodel;
+
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.ss.formula.ConditionalFormattingEvaluator;
+import org.apache.poi.ss.formula.EvaluationConditionalFormatRule;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.usermodel.XSSFColor;
+import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class ConditionalFormattingEvalTest {
+
+    private XSSFWorkbook wb;
+    private Sheet sheet;
+    private XSSFFormulaEvaluator formulaEval;
+    private ConditionalFormattingEvaluator cfe;
+    private CellReference ref;
+    private List<EvaluationConditionalFormatRule> rules;
+
+    @Before
+    public void openWB() {
+        wb = 
XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx");
+        formulaEval = new XSSFFormulaEvaluator(wb);
+        cfe = new ConditionalFormattingEvaluator(wb, formulaEval);
+    }
+    
+    @After
+    public void closeWB() {
+        formulaEval = null;
+        cfe = null;
+        ref = null;
+        rules = null;
+        try {
+            if (wb != null) wb.close();
+        } catch (IOException e) {
+            // keep going, this shouldn't cancel things
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testFormattingEvaluation() {
+        sheet = wb.getSheet("Products1");
+        
+        getRulesFor(12, 1);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        assertEquals("wrong bg color for " + ref, "FFFFEB9C", 
getColor(rules.get(0).getRule().getPatternFormatting().getFillBackgroundColorColor()));
+        assertFalse("should not be italic " + ref, 
rules.get(0).getRule().getFontFormatting().isItalic());
+        
+        getRulesFor(16, 3);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        assertEquals("wrong bg color for " + ref, 0.7999816888943144d, 
getTint(rules.get(0).getRule().getPatternFormatting().getFillBackgroundColorColor()),
 0.000000000000001);
+        
+        getRulesFor(12, 3);
+        assertEquals("wrong # of rules for " + ref, 0, rules.size());
+        
+        sheet = wb.getSheet("Products2");
+        
+        getRulesFor(15,1);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        assertEquals("wrong bg color for " + ref, "FFFFEB9C", 
getColor(rules.get(0).getRule().getPatternFormatting().getFillBackgroundColorColor()));
+
+        getRulesFor(20,3);
+        assertEquals("wrong # of rules for " + ref, 0, rules.size());
+
+        // now change a cell value that's an input for the rules
+        Cell cell = sheet.getRow(1).getCell(6);
+        cell.setCellValue("Dairy");
+        formulaEval.notifyUpdateCell(cell);
+        cell = sheet.getRow(4).getCell(6);
+        cell.setCellValue(500);
+        formulaEval.notifyUpdateCell(cell);
+        // need to throw away all evaluations, since we don't know how value 
changes may have affected format formulas
+        cfe.clearAllCachedValues();
+        
+        // test that the conditional validation evaluations changed
+        getRulesFor(15,1);
+        assertEquals("wrong # of rules for " + ref, 0, rules.size());
+        
+        getRulesFor(20,3);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        assertEquals("wrong bg color for " + ref, 0.7999816888943144d, 
getTint(rules.get(0).getRule().getPatternFormatting().getFillBackgroundColorColor()),
 0.000000000000001);
+        
+        getRulesFor(20,1);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        assertEquals("wrong bg color for " + ref, "FFFFEB9C", 
getColor(rules.get(0).getRule().getPatternFormatting().getFillBackgroundColorColor()));
+        
+        sheet = wb.getSheet("Book tour");
+        
+        getRulesFor(8,2);
+        assertEquals("wrong # of rules for " + ref, 1, rules.size());
+        
+    }
+    
+    private List<EvaluationConditionalFormatRule> getRulesFor(int row, int 
col) {
+        ref = new CellReference(sheet.getSheetName(), row, col, false, false);
+        return rules = cfe.getConditionalFormattingForCell(ref);
+    }
+    
+    private String getColor(Color color) {
+        final XSSFColor c = XSSFColor.toXSSFColor(color);
+        return c.getARGBHex();
+    }
+
+    private double getTint(Color color) {
+        final XSSFColor c = XSSFColor.toXSSFColor(color);
+        return c.getTint();
+    }
+}

Propchange: 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/ConditionalFormattingEvalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xls
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xls?rev=1782894&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xlsx
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xlsx?rev=1782894&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/ConditionalFormattingSamples.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/spreadsheet/DataValidationEvaluations.xlsx
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/DataValidationEvaluations.xlsx?rev=1782894&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/DataValidationEvaluations.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to