mirror of https://github.com/apache/poi.git
#58130 Enable CF ColorScale support on the rule, and begin testing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
01779c5721
commit
ca1dfbd1e5
|
@ -83,6 +83,11 @@ public interface ConditionalFormattingRule {
|
|||
*/
|
||||
IconMultiStateFormatting getMultiStateFormatting();
|
||||
|
||||
/**
|
||||
* @return color scale / color grate formatting object if defined, <code>null</code> otherwise
|
||||
*/
|
||||
ColorScaleFormatting getColorScaleFormatting();
|
||||
|
||||
/**
|
||||
* Type of conditional formatting rule.
|
||||
* <p>
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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<colors.length; i++) {
|
||||
Color c = color.getColors()[i];
|
||||
assertEquals(colors[i], c.toString());
|
||||
assertColour(colors[i], color.getColors()[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void testCreateFontFormatting() {
|
||||
|
@ -1068,6 +1068,13 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
|
|||
assertEquals(null, iconFmt.getThresholds()[3].getValue());
|
||||
}
|
||||
|
||||
public void testCreateColorScaleFormatting() {
|
||||
// TODO Implement then test
|
||||
}
|
||||
public void testCreateDataBarFormatting() {
|
||||
// TODO Implement then test
|
||||
}
|
||||
|
||||
public void testBug55380() {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
|
|
Loading…
Reference in New Issue