--- /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.xssf.usermodel;\r
+\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType;\r
+\r
+/**\r
+ * High level representation for Icon / Multi-State / Databar /\r
+ * Colour Scale change thresholds\r
+ */\r
+public class XSSFConditionalFormattingThreshold implements org.apache.poi.ss.usermodel.ConditionalFormattingThreshold {\r
+ private CTCfvo cfvo;\r
+\r
+ public RangeType getRangeType() {\r
+ return RangeType.valueOf(cfvo.getType().toString());\r
+ }\r
+ public void setRangeType(RangeType type) {\r
+ STCfvoType.Enum xtype = STCfvoType.Enum.forString(type.name);\r
+ cfvo.setType(xtype);\r
+ }\r
+\r
+ public String getFormula() {\r
+ if (cfvo.getType() == STCfvoType.FORMULA) {\r
+ return cfvo.getVal();\r
+ }\r
+ return null;\r
+ }\r
+ public void setFormula(String formula) {\r
+ cfvo.setVal(formula);\r
+ }\r
+\r
+ public Double getValue() {\r
+ if (cfvo.getType() == STCfvoType.FORMULA ||\r
+ cfvo.getType() == STCfvoType.MIN ||\r
+ cfvo.getType() == STCfvoType.MAX) {\r
+ return null;\r
+ }\r
+ if (cfvo.isSetVal()) {\r
+ return Double.parseDouble(cfvo.getVal());\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+ public void setValue(Double value) {\r
+ if (value == null) {\r
+ cfvo.unsetVal();\r
+ } else {\r
+ cfvo.setVal(value.toString());\r
+ }\r
+ }\r
+}\r
import org.apache.poi.ss.usermodel.ComparisonOperator;\r
import org.apache.poi.ss.usermodel.ConditionalFormatting;\r
import org.apache.poi.ss.usermodel.ConditionalFormattingRule;\r
+import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;\r
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;\r
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;\r
import org.apache.poi.ss.util.CellRangeAddress;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColorScale;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;\r
\r
/**\r
* XSSF Conditional Formattings\r
*/\r
public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) {\r
XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);\r
+ \r
+ // Mark it as being an Icon Set\r
CTCfRule cfRule = rule.getCTCfRule();\r
- cfRule.setType(STCfType.COLOR_SCALE);\r
+ cfRule.setType(STCfType.ICON_SET);\r
\r
+ // Set the type of the icon set\r
CTIconSet icons = cfRule.addNewIconSet();\r
if (iconSet.name != null) {\r
- // TODO Map to the enum\r
-// icons.setIconSet();\r
+ STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);\r
+ icons.setIconSet(xIconSet);\r
+ }\r
+ \r
+ // Add a default set of thresholds\r
+ int jump = 100 / iconSet.num;\r
+ STCfvoType.Enum type = STCfvoType.Enum.forString(RangeType.PERCENT.name);\r
+ for (int i=0; i<iconSet.num; i++) {\r
+ CTCfvo cfvo = icons.addNewCfvo();\r
+ cfvo.setType(type);\r
+ cfvo.setVal(Integer.toString(i*jump));\r
}\r
- // TODO Add cfvos\r
\r
+ // All done!\r
return rule;\r
}\r
\r