mirror of https://github.com/apache/poi.git
XSSF CF thresholds
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03349cb8ff
commit
0cabf8ae6e
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<iconSet.num; i++) {
|
||||
CTCfvo cfvo = icons.addNewCfvo();
|
||||
cfvo.setType(type);
|
||||
cfvo.setVal(Integer.toString(i*jump));
|
||||
}
|
||||
|
||||
// All done!
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue