git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691113 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_13_BETA1
@@ -173,6 +173,14 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord { | |||
public IconMultiStateFormatting getMultiStateFormatting() { | |||
return multistate; | |||
} | |||
public IconMultiStateFormatting createMultiStateFormatting() { | |||
if (multistate != null) return multistate; | |||
// Convert, setup and return | |||
setConditionType(CONDITION_TYPE_ICON_SET); | |||
multistate = new IconMultiStateFormatting(); | |||
return multistate; | |||
} | |||
/** | |||
* get the stack of the scale expression as a list |
@@ -18,11 +18,13 @@ | |||
package org.apache.poi.hssf.usermodel; | |||
import org.apache.poi.hssf.model.HSSFFormulaParser; | |||
import org.apache.poi.hssf.record.CFRule12Record; | |||
import org.apache.poi.hssf.record.CFRuleBase; | |||
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator; | |||
import org.apache.poi.hssf.record.CFRuleRecord; | |||
import org.apache.poi.hssf.record.cf.BorderFormatting; | |||
import org.apache.poi.hssf.record.cf.FontFormatting; | |||
import org.apache.poi.hssf.record.cf.IconMultiStateFormatting; | |||
import org.apache.poi.hssf.record.cf.PatternFormatting; | |||
import org.apache.poi.ss.formula.ptg.Ptg; | |||
import org.apache.poi.ss.usermodel.ConditionType; | |||
@@ -165,7 +167,46 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin | |||
{ | |||
return getPatternFormatting(true); | |||
} | |||
private HSSFIconMultiStateFormatting getMultiStateFormatting(boolean create) { | |||
if (cfRuleRecord instanceof CFRule12Record) { | |||
// Good | |||
} else { | |||
if (create) throw new IllegalArgumentException("Can't convert a CF into a CF12 record"); | |||
return null; | |||
} | |||
CFRule12Record cfRule12Record = (CFRule12Record)cfRuleRecord; | |||
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting(); | |||
if (iconFormatting != null) | |||
{ | |||
return new HSSFIconMultiStateFormatting(cfRule12Record); | |||
} | |||
else if( create ) | |||
{ | |||
iconFormatting = cfRule12Record.createMultiStateFormatting(); | |||
return new HSSFIconMultiStateFormatting(cfRule12Record); | |||
} | |||
else | |||
{ | |||
return null; | |||
} | |||
} | |||
/** | |||
* @return icon / multi-state formatting object if defined, <code>null</code> otherwise | |||
*/ | |||
public HSSFIconMultiStateFormatting getMultiStateFormatting() { | |||
return getMultiStateFormatting(false); | |||
} | |||
/** | |||
* create a new icon / multi-state formatting object if it does not exist, | |||
* otherwise just return the existing object. | |||
*/ | |||
public HSSFIconMultiStateFormatting createMultiStateFormatting() { | |||
return getMultiStateFormatting(true); | |||
} | |||
/** | |||
* @return - the conditiontype for the cfrule | |||
*/ | |||
@@ -205,7 +246,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin | |||
} | |||
private String toFormulaString(Ptg[] parsedExpression) { | |||
if(parsedExpression ==null) { | |||
if(parsedExpression == null || parsedExpression.length == 0) { | |||
return null; | |||
} | |||
return HSSFFormulaParser.toFormulaString(workbook, parsedExpression); |
@@ -17,6 +17,7 @@ | |||
package org.apache.poi.hssf.usermodel; | |||
import org.apache.poi.hssf.record.CFRule12Record; | |||
import org.apache.poi.hssf.record.CFRuleBase; | |||
import org.apache.poi.hssf.record.CFRuleRecord; | |||
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; | |||
@@ -24,6 +25,7 @@ import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable; | |||
import org.apache.poi.ss.SpreadsheetVersion; | |||
import org.apache.poi.ss.usermodel.ConditionalFormatting; | |||
import org.apache.poi.ss.usermodel.ConditionalFormattingRule; | |||
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet; | |||
import org.apache.poi.ss.usermodel.SheetConditionalFormatting; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
@@ -94,6 +96,20 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor | |||
CFRuleRecord rr = CFRuleRecord.create(_sheet, formula); | |||
return new HSSFConditionalFormattingRule(wb, rr); | |||
} | |||
/** | |||
* A factory method allowing the creation of conditional formatting | |||
* rules using an Icon Set / Multi-State formatting/ | |||
*/ | |||
// TODO Implement | |||
/* | |||
public HSSFConditionalFormattingRule createConditionalFormattingRule( | |||
IconSet iconSet) { // TODO Multi-State data for it | |||
HSSFWorkbook wb = _sheet.getWorkbook(); | |||
CFRule12Record rr = CFRule12Record.create(_sheet, iconSet); | |||
return new HSSFConditionalFormattingRule(wb, rr); | |||
} | |||
*/ | |||
/** | |||
* Adds a copy of HSSFConditionalFormatting object to the sheet |
@@ -24,6 +24,7 @@ import junit.framework.TestCase; | |||
import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting; | |||
import org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule; | |||
import org.apache.poi.ss.ITestDataProvider; | |||
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
/** | |||
@@ -544,6 +545,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase { | |||
Sheet s = wb.getSheet("CF"); | |||
ConditionalFormatting cf = null; | |||
ConditionalFormattingRule cr = null; | |||
IconMultiStateFormatting icon = null; | |||
// Sanity check data | |||
assertEquals("Values", s.getRow(0).getCell(0).toString()); | |||
@@ -644,7 +646,30 @@ public abstract class BaseTestConditionalFormatting extends TestCase { | |||
// Colours R->G - Column F | |||
// Colours BWR - Column G | |||
// Icons : Default - Column H | |||
cf = sheetCF.getConditionalFormattingAt(5); | |||
assertEquals(1, cf.getFormattingRanges().length); | |||
assertEquals("H2:H17", cf.getFormattingRanges()[0].formatAsString()); | |||
assertEquals(1, cf.getNumberOfRules()); | |||
cr = cf.getRule(0); | |||
assertEquals(ConditionType.ICON_SET, cr.getConditionTypeType()); | |||
assertEquals(ComparisonOperator.NO_COMPARISON, cr.getComparisonOperation()); | |||
assertEquals(null, cr.getFormula1()); | |||
assertEquals(null, cr.getFormula2()); | |||
if (cr instanceof HSSFConditionalFormattingRule) { | |||
HSSFConditionalFormattingRule hcr = (HSSFConditionalFormattingRule)cr; | |||
icon = hcr.getMultiStateFormatting(); | |||
assertNotNull(icon); | |||
assertEquals(IconSet.GYR_3_TRAFFIC_LIGHTS, icon.getIconSet()); | |||
assertEquals(false, icon.isIconOnly()); | |||
assertEquals(false, icon.isReversed()); | |||
// TODO Check the rest | |||
} else { | |||
// TODO XSSF Support | |||
} | |||
// Icons : 3 signs - Column I | |||
// Icons : 3 traffic lights 2 - Column J | |||
// Icons : 4 traffic lights - Column K | |||
@@ -834,6 +859,10 @@ public abstract class BaseTestConditionalFormatting extends TestCase { | |||
assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight()); | |||
} | |||
public void testCreateIconFormatting() { | |||
// TODO Implement for XSSF, then test here | |||
} | |||
public void testBug55380() { | |||
Workbook wb = _testDataProvider.createWorkbook(); | |||
Sheet sheet = wb.createSheet(); |