]> source.dussan.org Git - poi.git/commitdiff
XSSF CF thresholds
authorNick Burch <nick@apache.org>
Fri, 17 Jul 2015 02:41:20 +0000 (02:41 +0000)
committerNick Burch <nick@apache.org>
Fri, 17 Jul 2015 02:41:20 +0000 (02:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691478 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java

diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.java
new file mode 100644 (file)
index 0000000..254e8c0
--- /dev/null
@@ -0,0 +1,69 @@
+/*\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
index 23d5f39f8edeac7c93f29e8cca03e3574e46a898..7ff6cfc2ceed80caa0b7529abf53f8425cf8ff9f 100644 (file)
@@ -27,16 +27,19 @@ import org.apache.poi.ss.SpreadsheetVersion;
 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
@@ -132,16 +135,28 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
      */\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