]> source.dussan.org Git - poi.git/commitdiff
Expose Priority from newer-style HSSF CF rules
authorNick Burch <nick@apache.org>
Tue, 14 Feb 2017 17:49:13 +0000 (17:49 +0000)
committerNick Burch <nick@apache.org>
Tue, 14 Feb 2017 17:49:13 +0000 (17:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782995 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/CFRule12Record.java
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java

index fd4cafa76dfaec62d4216a35c5a6cf3568c271af..d9d9793e9b20aa90ae2af0122067ae1fc2500612 100644 (file)
@@ -331,6 +331,13 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord, Cl
         formula_scale = Formula.create(ptgs);
     }
 
+    public int getPriority() {
+        return priority;
+    }
+    public void setPriority(int priority) {
+        this.priority = priority;
+    }
+
     public short getSid() {
         return sid;
     }
index 83a5b2569f98104886809b9070d5e27cb34c4bb0..aa4631509157dfcb03f0a69cfec9e037b6561690 100644 (file)
@@ -60,11 +60,15 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
     }
 
     /**
-     * we don't know priority for these, other than definition/model order, which appears to be what Excel uses.
+     * Only newer style formatting rules have priorities. For older ones,
+     *  we don't know priority for these, other than definition/model order, 
+     *  which appears to be what Excel uses.
      * @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getPriority()
      */
     public int getPriority() {
-        return 0;
+        CFRule12Record rule12 = getCFRule12Record(false);
+        if (rule12 == null) return 0;
+        return rule12.getPriority();
     }
     
     /**
index 54961ca6d092f08b4c9803f28dbe4e8c15330017..da3896bd05a2ad1a148a64af96a9545a9ef264de 100644 (file)
@@ -147,10 +147,13 @@ public interface ConditionalFormattingRule {
     String getFormula2();
 
     /**
-     * HSSF just returns 0, XSSF uses the value stored in the model if present, 
-     * otherwise uses 0.
+     * The priority of the rule, if defined, otherwise 0.
      * <p/>
-     * If priority is 0, just use definition order, as that's how HSSF rules are evaluated.
+     * If priority is 0, just use definition order, as that's how older HSSF rules 
+     *  are evaluated.
+     * <p/>
+     * For XSSF, this should always be set. For HSSF, only newer style rules
+     *  have this set, older ones will return 0.
      * <p/>
      * If a rule is created but not yet added to a sheet, this value may not be valid.
      * @return rule priority