diff --git a/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java b/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
index 5fb315147e..6f71b7b636 100644
--- a/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
+++ b/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
@@ -83,6 +83,11 @@ public interface ConditionalFormattingRule {
*/
IconMultiStateFormatting getMultiStateFormatting();
+ /**
+ * @return color scale / color grate formatting object if defined, null
otherwise
+ */
+ ColorScaleFormatting getColorScaleFormatting();
+
/**
* Type of conditional formatting rule.
*
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 f396a5dc8a..2523991403 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
@@ -60,8 +60,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);
}
- // TODO Support types beyond CELL_VALUE_IS and FORMULA
-
/*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){
_cfRule = CTCfRule.Factory.newInstance();
_sh = sh;
@@ -218,8 +216,39 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
}
public XSSFColorScaleFormatting createColorScaleFormatting() {
- // TODO Implement
- return null;
+ // Is it already there?
+ if (_cfRule.isSetColorScale() && _cfRule.getType() == STCfType.COLOR_SCALE)
+ return getColorScaleFormatting();
+
+ // Mark it as being a Color Scale
+ _cfRule.setType(STCfType.COLOR_SCALE);
+
+ // Ensure the right element
+ CTColorScale scale = null;
+ if (_cfRule.isSetColorScale()) {
+ scale = _cfRule.getColorScale();
+ } else {
+ scale = _cfRule.addNewColorScale();
+ }
+
+ // Add a default set of thresholds and colors
+ if (scale.sizeOfCfvoArray() == 0) {
+ CTCfvo cfvo;
+ cfvo = scale.addNewCfvo();
+ cfvo.setType(STCfvoType.Enum.forString(RangeType.MIN.name));
+ cfvo = scale.addNewCfvo();
+ cfvo.setType(STCfvoType.Enum.forString(RangeType.PERCENTILE.name));
+ cfvo.setVal("50");
+ cfvo = scale.addNewCfvo();
+ cfvo.setType(STCfvoType.Enum.forString(RangeType.MAX.name));
+
+ for (int i=0; i<3; i++) {
+ scale.addNewColor();
+ }
+ }
+
+ // Wrap and return
+ return new XSSFColorScaleFormatting(scale);
}
public XSSFColorScaleFormatting getColorScaleFormatting() {
if (_cfRule.isSetColorScale()) {
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
index 1a130b7510..0d4c9d0520 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
@@ -773,6 +773,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
// Mixed icons - Column U
// TODO Support EXT formattings
}
+
private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) {
assertEquals(1, cf.getNumberOfRules());
ConditionalFormattingRule cr = cf.getRule(0);
@@ -812,8 +813,9 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
assertEquals(null, cr.getFormula1());
assertEquals(null, cr.getFormula2());
- // TODO Implement
-/*
+// TODO Finish HSSF
+if (cr instanceof HSSFConditionalFormattingRule) return;
+
ColorScaleFormatting color = cr.getColorScaleFormatting();
assertNotNull(color);
assertNotNull(color.getColors());
@@ -831,18 +833,16 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
} else if (i == colors.length-1) {
assertEquals(RangeType.MAX, th.getRangeType());
} else {
- assertEquals(RangeType.PERCENT, th.getRangeType());
- assertEquals(steps*i, th.getValue());
+ assertEquals(RangeType.PERCENTILE, th.getRangeType());
+ assertEquals(steps*i, th.getValue().intValue());
}
assertEquals(null, th.getFormula());
}
// Colors should match
for (int i=0; i