diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java index 93af503de..b87d8813c 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java @@ -25,6 +25,7 @@ import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.record.cf.FontFormatting; import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.ss.usermodel.ConditionType; import org.apache.poi.ss.usermodel.ConditionalFormattingRule; /** @@ -33,8 +34,7 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingRule; * It allows to specify formula based conditions for the Conditional Formatting * and the formatting settings such as font, border and pattern. */ -public final class HSSFConditionalFormattingRule implements ConditionalFormattingRule -{ +public final class HSSFConditionalFormattingRule implements ConditionalFormattingRule { private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS; private final CFRuleBase cfRuleRecord; @@ -172,6 +172,12 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin public byte getConditionType() { return cfRuleRecord.getConditionType(); } + /** + * @return - the conditiontype for the cfrule + */ + public ConditionType getConditionTypeType() { + return ConditionType.forId(getConditionType()); + } /** * @return - the comparisionoperatation for the cfrule diff --git a/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java b/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java index 7e29cbf4c..7eee78903 100644 --- a/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java +++ b/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java @@ -24,9 +24,6 @@ package org.apache.poi.ss.usermodel; *
* For example, "highlight cells that begin with "M2" and contain "Mountain Gear". *
- * - * @author Dmitriy Kumshayev - * @author Yegor Kozlov */ public final class ComparisonOperator { public static final byte NO_COMPARISON = 0; diff --git a/src/java/org/apache/poi/ss/usermodel/ConditionType.java b/src/java/org/apache/poi/ss/usermodel/ConditionType.java new file mode 100644 index 000000000..4f8de4f67 --- /dev/null +++ b/src/java/org/apache/poi/ss/usermodel/ConditionType.java @@ -0,0 +1,88 @@ +/* + * ==================================================================== + * 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; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents a type of a conditional formatting rule + */ +public class ConditionType { + private static Map- * MUST be either {@link #CONDITION_TYPE_CELL_VALUE_IS} or {@link #CONDITION_TYPE_FORMULA} + * MUST be one of the IDs of a {@link ConditionType} *
* * @return the type of condition + * @deprecated Use {@link #getConditionTypeType()} */ byte getConditionType(); + + /** + * Type of conditional formatting rule. + * + * @return the type of condition + */ + ConditionType getConditionTypeType(); /** * The comparison function used when the type of conditional formatting is set to diff --git a/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java b/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java index 6d8c328c0..7f54f3015 100644 --- a/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java +++ b/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java @@ -83,7 +83,7 @@ public interface SheetConditionalFormatting { ** The created conditional formatting rule compares a cell value * to a formula calculated result, using the specified operator. - * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS} + * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS} *
* * @param comparisonOperation - MUST be a constant value from @@ -112,7 +112,7 @@ public interface SheetConditionalFormatting { * Create a conditional formatting rule that compares a cell value * to a formula calculated result, using an operator * *- * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS} + * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS} *
* * @param comparisonOperation MUST be a constant value from @@ -129,7 +129,7 @@ public interface SheetConditionalFormatting { * When the formula result is true, the cell is highlighted. * *- * The type of the created format condition is {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA} + * The type of the created format condition is {@link ConditionalFormattingRule#CONDITION_FORMULA} *
* @param formula the formula to evaluate. MUST be a Boolean function. */ diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java index 64e49f947..0b4a05d09 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java @@ -19,6 +19,9 @@ package org.apache.poi.xssf.usermodel; +import java.util.HashMap; +import java.util.Map; + import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFFontFormatting; import org.apache.poi.xssf.model.StylesTable; @@ -36,6 +39,30 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; public class XSSFConditionalFormattingRule implements ConditionalFormattingRule { private final CTCfRule _cfRule; private XSSFSheet _sh; + + private static Map- * MUST be either {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS} - * or {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA} + * MUST be one of the IDs of a {@link ConditionType} *
* * @return the type of condition */ public byte getConditionType(){ - switch (_cfRule.getType().intValue()){ - case STCfType.INT_EXPRESSION: return ConditionalFormattingRule.CONDITION_TYPE_FORMULA; - case STCfType.INT_CELL_IS: return ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS; - } + ConditionType type = getConditionTypeType(); + if (type != null) return type.id; return 0; } + + /** + * Type of conditional formatting rule. + */ + public ConditionType getConditionTypeType() { + return typeLookup.get(_cfRule.getType()); + } /** * The comparison function used when the type of conditional formatting is set to