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;
/**
* 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;
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
* <p>\r
* For example, "highlight cells that begin with "M2" and contain "Mountain Gear".\r
* </p>\r
- *\r
- * @author Dmitriy Kumshayev\r
- * @author Yegor Kozlov\r
*/\r
public final class ComparisonOperator {\r
public static final byte NO_COMPARISON = 0;\r
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.ss.usermodel;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+/**\r
+ * Represents a type of a conditional formatting rule\r
+ */\r
+public class ConditionType {\r
+ private static Map<Integer,ConditionType> lookup = new HashMap<Integer, ConditionType>();\r
+ \r
+ /**\r
+ * This conditional formatting rule compares a cell value\r
+ * to a formula calculated result, using an operator\r
+ */\r
+ public static final ConditionType CELL_VALUE_IS = \r
+ new ConditionType(1, "cellIs");\r
+\r
+ /**\r
+ * This conditional formatting rule contains a formula to evaluate.\r
+ * When the formula result is true, the cell is highlighted.\r
+ */\r
+ public static final ConditionType FORMULA = \r
+ new ConditionType(2, "expression");\r
+ \r
+ /**\r
+ * This conditional formatting rule contains a color scale,\r
+ * with the cell background set according to a gradient.\r
+ */\r
+ public static final ConditionType COLOR_SCALE = \r
+ new ConditionType(3, "colorScale");\r
+ \r
+ /**\r
+ * This conditional formatting rule sets a data bar, with the\r
+ * cell populated with bars based on their values\r
+ */\r
+ public static final ConditionType DATA_BAR = \r
+ new ConditionType(4, "dataBar");\r
+ \r
+ /**\r
+ * This conditional formatting rule that files the values\r
+ */\r
+ public static final ConditionType FILTER = \r
+ new ConditionType(5, null);\r
+ \r
+ /**\r
+ * This conditional formatting rule sets a data bar, with the\r
+ * cell populated with bars based on their values\r
+ */\r
+ public static final ConditionType ICON_SET = \r
+ new ConditionType(6, "iconSet");\r
+ \r
+ \r
+ public final byte id;\r
+ public final String type;\r
+\r
+ \r
+ public static ConditionType forId(byte id) {\r
+ return forId((int)id);\r
+ }\r
+ public static ConditionType forId(int id) {\r
+ return lookup.get(id);\r
+ }\r
+ \r
+ private ConditionType(int id, String type) {\r
+ this.id = (byte)id; this.type = type;\r
+ lookup.put(id, this);\r
+ }\r
+}\r
\r
package org.apache.poi.ss.usermodel;\r
\r
+import static org.apache.poi.ss.usermodel.ConditionType.*;\r
+\r
/**\r
* Represents a description of a conditional formatting rule\r
*/\r
/**\r
* This conditional formatting rule compares a cell value\r
* to a formula calculated result, using an operator\r
+ * @deprecated Use {@link ConditionType#CELL_VALUE_IS}\r
*/\r
- public static final byte CONDITION_TYPE_CELL_VALUE_IS = 1;\r
+ public static final byte CONDITION_TYPE_CELL_VALUE_IS = CELL_VALUE_IS.id;\r
\r
/**\r
* This conditional formatting rule contains a formula to evaluate.\r
* When the formula result is true, the cell is highlighted.\r
+ * @deprecated Use {@link ConditionType#FORMULA}\r
*/\r
- public static final byte CONDITION_TYPE_FORMULA = 2;\r
+ public static final byte CONDITION_TYPE_FORMULA = FORMULA.id;\r
\r
/**\r
* Create a new border formatting structure if it does not exist,\r
/**\r
* Type of conditional formatting rule.\r
* <p>\r
- * MUST be either {@link #CONDITION_TYPE_CELL_VALUE_IS} or {@link #CONDITION_TYPE_FORMULA}\r
+ * MUST be one of the IDs of a {@link ConditionType}\r
* </p>\r
*\r
* @return the type of condition\r
+ * @deprecated Use {@link #getConditionTypeType()}\r
*/\r
byte getConditionType();\r
+ \r
+ /**\r
+ * Type of conditional formatting rule.\r
+ *\r
+ * @return the type of condition\r
+ */\r
+ ConditionType getConditionTypeType();\r
\r
/**\r
* The comparison function used when the type of conditional formatting is set to\r
* <p>\r
* The created conditional formatting rule compares a cell value\r
* to a formula calculated result, using the specified operator.\r
- * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}\r
+ * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS}\r
* </p>\r
*\r
* @param comparisonOperation - MUST be a constant value from\r
* Create a conditional formatting rule that compares a cell value\r
* to a formula calculated result, using an operator *\r
* <p>\r
- * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}\r
+ * The type of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS}\r
* </p>\r
*\r
* @param comparisonOperation MUST be a constant value from\r
* When the formula result is true, the cell is highlighted.\r
*\r
* <p>\r
- * The type of the created format condition is {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA}\r
+ * The type of the created format condition is {@link ConditionalFormattingRule#CONDITION_FORMULA}\r
* </p>\r
* @param formula the formula to evaluate. MUST be a Boolean function.\r
*/\r
\r
package org.apache.poi.xssf.usermodel;\r
\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
import org.apache.poi.ss.usermodel.*;\r
import org.apache.poi.xssf.usermodel.XSSFFontFormatting;\r
import org.apache.poi.xssf.model.StylesTable;\r
public class XSSFConditionalFormattingRule implements ConditionalFormattingRule {\r
private final CTCfRule _cfRule;\r
private XSSFSheet _sh;\r
+ \r
+ private static Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<STCfType.Enum, ConditionType>();\r
+ static {\r
+ typeLookup.put(STCfType.CELL_IS, ConditionType.CELL_VALUE_IS);\r
+ typeLookup.put(STCfType.EXPRESSION, ConditionType.FORMULA);\r
+ typeLookup.put(STCfType.COLOR_SCALE, ConditionType.COLOR_SCALE);\r
+ typeLookup.put(STCfType.DATA_BAR, ConditionType.DATA_BAR);\r
+ typeLookup.put(STCfType.ICON_SET, ConditionType.ICON_SET);\r
+ \r
+ // These are all subtypes of Filter, we think...\r
+ typeLookup.put(STCfType.TOP_10, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.UNIQUE_VALUES, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.DUPLICATE_VALUES, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.CONTAINS_TEXT, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.NOT_CONTAINS_TEXT, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.BEGINS_WITH, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.ENDS_WITH, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.CONTAINS_BLANKS, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.NOT_CONTAINS_BLANKS, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.CONTAINS_ERRORS, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.NOT_CONTAINS_ERRORS, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.TIME_PERIOD, ConditionType.FILTER);\r
+ typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);\r
+ }\r
\r
/*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){\r
_cfRule = CTCfRule.Factory.newInstance();\r
/**\r
* Type of conditional formatting rule.\r
* <p>\r
- * MUST be either {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}\r
- * or {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA}\r
+ * MUST be one of the IDs of a {@link ConditionType}\r
* </p>\r
*\r
* @return the type of condition\r
*/\r
public byte getConditionType(){\r
- switch (_cfRule.getType().intValue()){\r
- case STCfType.INT_EXPRESSION: return ConditionalFormattingRule.CONDITION_TYPE_FORMULA;\r
- case STCfType.INT_CELL_IS: return ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS;\r
- }\r
+ ConditionType type = getConditionTypeType();\r
+ if (type != null) return type.id;\r
return 0;\r
}\r
+ \r
+ /**\r
+ * Type of conditional formatting rule.\r
+ */\r
+ public ConditionType getConditionTypeType() {\r
+ return typeLookup.get(_cfRule.getType());\r
+ }\r
\r
/**\r
* The comparison function used when the type of conditional formatting is set to\r