Start on XSSF CF Iconset for #58130
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a22ab7249f
commit
4780ccf161
@ -23,15 +23,11 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
|
||||||
|
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFFontFormatting;
|
import org.apache.poi.xssf.usermodel.XSSFFontFormatting;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XSSF suport for Conditional Formatting rules
|
* XSSF suport for Conditional Formatting rules
|
||||||
@ -179,12 +175,46 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
|
|||||||
return new XSSFPatternFormatting(dxf.getFill());
|
return new XSSFPatternFormatting(dxf.getFill());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XSSFIconMultiStateFormatting createMultiStateFormatting(IconSet iconSet) {
|
||||||
|
// Is it already there?
|
||||||
|
if (_cfRule.isSetIconSet() && _cfRule.getType() == STCfType.ICON_SET)
|
||||||
|
return getMultiStateFormatting();
|
||||||
|
|
||||||
public IconMultiStateFormatting createMultiStateFormatting() {
|
// Mark it as being an Icon Set
|
||||||
throw new IllegalArgumentException("Not implemented yet"); // TODO
|
_cfRule.setType(STCfType.ICON_SET);
|
||||||
|
|
||||||
|
// Ensure the right element
|
||||||
|
CTIconSet icons = null;
|
||||||
|
if (_cfRule.isSetIconSet()) {
|
||||||
|
icons = _cfRule.getIconSet();
|
||||||
|
} else {
|
||||||
|
icons = _cfRule.addNewIconSet();
|
||||||
|
}
|
||||||
|
// Set the type of the icon set
|
||||||
|
if (iconSet.name != null) {
|
||||||
|
STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);
|
||||||
|
icons.setIconSet(xIconSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap and return
|
||||||
|
return new XSSFIconMultiStateFormatting(icons);
|
||||||
|
}
|
||||||
|
public XSSFIconMultiStateFormatting getMultiStateFormatting() {
|
||||||
|
if (_cfRule.isSetIconSet()) {
|
||||||
|
CTIconSet icons = _cfRule.getIconSet();
|
||||||
|
return new XSSFIconMultiStateFormatting(icons);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public IconMultiStateFormatting getMultiStateFormatting() {
|
|
||||||
throw new IllegalArgumentException("Not implemented yet"); // TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.apache.poi.ss.usermodel.ConditionalFormattingThreshold;
|
||||||
|
import org.apache.poi.ss.usermodel.IconMultiStateFormatting;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* High level representation for Icon / Multi-State Formatting
|
||||||
|
* component of Conditional Formatting settings
|
||||||
|
*/
|
||||||
|
public class XSSFIconMultiStateFormatting implements IconMultiStateFormatting {
|
||||||
|
CTIconSet _iconset;
|
||||||
|
|
||||||
|
/*package*/ XSSFIconMultiStateFormatting(CTIconSet iconset){
|
||||||
|
_iconset = iconset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconSet getIconSet() {
|
||||||
|
return IconSet.valueOf(
|
||||||
|
_iconset.getIconSet().toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public void setIconSet(IconSet set) {
|
||||||
|
STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(set.name);
|
||||||
|
_iconset.setIconSet(xIconSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIconOnly() {
|
||||||
|
if (_iconset.isSetShowValue())
|
||||||
|
return !_iconset.getShowValue();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void setIconOnly(boolean only) {
|
||||||
|
_iconset.setShowValue(!only);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReversed() {
|
||||||
|
if (_iconset.isSetReverse())
|
||||||
|
return _iconset.getReverse();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void setReversed(boolean reversed) {
|
||||||
|
_iconset.setReverse(reversed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFConditionalFormattingThreshold[] getThresholds() {
|
||||||
|
// TODO Implement
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void setThresholds(ConditionalFormattingThreshold[] thresholds) {
|
||||||
|
// TODO Implement
|
||||||
|
}
|
||||||
|
}
|
@ -27,19 +27,14 @@ import org.apache.poi.ss.SpreadsheetVersion;
|
|||||||
import org.apache.poi.ss.usermodel.ComparisonOperator;
|
import org.apache.poi.ss.usermodel.ComparisonOperator;
|
||||||
import org.apache.poi.ss.usermodel.ConditionalFormatting;
|
import org.apache.poi.ss.usermodel.ConditionalFormatting;
|
||||||
import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
|
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.IconMultiStateFormatting.IconSet;
|
||||||
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
|
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
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.CTWorksheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
|
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.STConditionalFormattingOperator;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XSSF Conditional Formattings
|
* XSSF Conditional Formattings
|
||||||
@ -136,25 +131,8 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
|
|||||||
public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) {
|
public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) {
|
||||||
XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);
|
XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);
|
||||||
|
|
||||||
// Mark it as being an Icon Set
|
// Have it setup, with suitable defaults
|
||||||
CTCfRule cfRule = rule.getCTCfRule();
|
rule.createMultiStateFormatting(iconSet);
|
||||||
cfRule.setType(STCfType.ICON_SET);
|
|
||||||
|
|
||||||
// Set the type of the icon set
|
|
||||||
CTIconSet icons = cfRule.addNewIconSet();
|
|
||||||
if (iconSet.name != null) {
|
|
||||||
STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);
|
|
||||||
icons.setIconSet(xIconSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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!
|
// All done!
|
||||||
return rule;
|
return rule;
|
||||||
|
Loading…
Reference in New Issue
Block a user