From 0cabf8ae6e2eb6a2a9a72613eb43f82ea33cd6b9 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 17 Jul 2015 02:41:20 +0000 Subject: [PATCH] XSSF CF thresholds git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691478 13f79535-47bb-0310-9956-ffa450edef68 --- .../XSSFConditionalFormattingThreshold.java | 69 +++++++++++++++++++ .../XSSFSheetConditionalFormatting.java | 25 +++++-- 2 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.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 index 0000000000..254e8c0a8f --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.java @@ -0,0 +1,69 @@ +/* + * ==================================================================== + * 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.xssf.usermodel; + +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType; + +/** + * High level representation for Icon / Multi-State / Databar / + * Colour Scale change thresholds + */ +public class XSSFConditionalFormattingThreshold implements org.apache.poi.ss.usermodel.ConditionalFormattingThreshold { + private CTCfvo cfvo; + + public RangeType getRangeType() { + return RangeType.valueOf(cfvo.getType().toString()); + } + public void setRangeType(RangeType type) { + STCfvoType.Enum xtype = STCfvoType.Enum.forString(type.name); + cfvo.setType(xtype); + } + + public String getFormula() { + if (cfvo.getType() == STCfvoType.FORMULA) { + return cfvo.getVal(); + } + return null; + } + public void setFormula(String formula) { + cfvo.setVal(formula); + } + + public Double getValue() { + if (cfvo.getType() == STCfvoType.FORMULA || + cfvo.getType() == STCfvoType.MIN || + cfvo.getType() == STCfvoType.MAX) { + return null; + } + if (cfvo.isSetVal()) { + return Double.parseDouble(cfvo.getVal()); + } else { + return null; + } + } + public void setValue(Double value) { + if (value == null) { + cfvo.unsetVal(); + } else { + cfvo.setVal(value.toString()); + } + } +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java index 23d5f39f8e..7ff6cfc2ce 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java @@ -27,16 +27,19 @@ import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.ComparisonOperator; import org.apache.poi.ss.usermodel.ConditionalFormatting; import org.apache.poi.ss.usermodel.ConditionalFormattingRule; +import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType; import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet; import org.apache.poi.ss.usermodel.SheetConditionalFormatting; import org.apache.poi.ss.util.CellRangeAddress; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColorScale; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType; /** * XSSF Conditional Formattings @@ -132,16 +135,28 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin */ public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) { XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet); + + // Mark it as being an Icon Set CTCfRule cfRule = rule.getCTCfRule(); - cfRule.setType(STCfType.COLOR_SCALE); + cfRule.setType(STCfType.ICON_SET); + // Set the type of the icon set CTIconSet icons = cfRule.addNewIconSet(); if (iconSet.name != null) { - // TODO Map to the enum -// icons.setIconSet(); + STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name); + icons.setIconSet(xIconSet); } - // TODO Add cfvos + // Add a default set of thresholds + int jump = 100 / iconSet.num; + STCfvoType.Enum type = STCfvoType.Enum.forString(RangeType.PERCENT.name); + for (int i=0; i