From 4780ccf161e3c4dd854cdf446f0f51659ffe71f1 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 17 Jul 2015 02:55:22 +0000 Subject: [PATCH] Start on XSSF CF Iconset for #58130 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691479 13f79535-47bb-0310-9956-ffa450edef68 --- .../XSSFConditionalFormattingRule.java | 52 +++++++++++--- .../XSSFIconMultiStateFormatting.java | 72 +++++++++++++++++++ .../XSSFSheetConditionalFormatting.java | 26 +------ 3 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java index a1386e400..814e73ca0 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java @@ -23,15 +23,11 @@ import java.util.HashMap; import java.util.Map; 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.model.StylesTable; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule; -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; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; /** * XSSF suport for Conditional Formatting rules @@ -179,12 +175,46 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule return new XSSFPatternFormatting(dxf.getFill()); } + public XSSFIconMultiStateFormatting createMultiStateFormatting(IconSet iconSet) { + // Is it already there? + if (_cfRule.isSetIconSet() && _cfRule.getType() == STCfType.ICON_SET) + return getMultiStateFormatting(); + + // Mark it as being an Icon Set + _cfRule.setType(STCfType.ICON_SET); - public IconMultiStateFormatting createMultiStateFormatting() { - throw new IllegalArgumentException("Not implemented yet"); // TODO + // 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