git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691113 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_13_BETA1
public IconMultiStateFormatting getMultiStateFormatting() { | public IconMultiStateFormatting getMultiStateFormatting() { | ||||
return multistate; | 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 | * get the stack of the scale expression as a list |
package org.apache.poi.hssf.usermodel; | package org.apache.poi.hssf.usermodel; | ||||
import org.apache.poi.hssf.model.HSSFFormulaParser; | 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; | ||||
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator; | import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator; | ||||
import org.apache.poi.hssf.record.CFRuleRecord; | import org.apache.poi.hssf.record.CFRuleRecord; | ||||
import org.apache.poi.hssf.record.cf.BorderFormatting; | import org.apache.poi.hssf.record.cf.BorderFormatting; | ||||
import org.apache.poi.hssf.record.cf.FontFormatting; | 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.hssf.record.cf.PatternFormatting; | ||||
import org.apache.poi.ss.formula.ptg.Ptg; | import org.apache.poi.ss.formula.ptg.Ptg; | ||||
import org.apache.poi.ss.usermodel.ConditionType; | import org.apache.poi.ss.usermodel.ConditionType; | ||||
{ | { | ||||
return getPatternFormatting(true); | 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 | * @return - the conditiontype for the cfrule | ||||
*/ | */ | ||||
} | } | ||||
private String toFormulaString(Ptg[] parsedExpression) { | private String toFormulaString(Ptg[] parsedExpression) { | ||||
if(parsedExpression ==null) { | |||||
if(parsedExpression == null || parsedExpression.length == 0) { | |||||
return null; | return null; | ||||
} | } | ||||
return HSSFFormulaParser.toFormulaString(workbook, parsedExpression); | return HSSFFormulaParser.toFormulaString(workbook, parsedExpression); |
package org.apache.poi.hssf.usermodel; | 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.CFRuleBase; | ||||
import org.apache.poi.hssf.record.CFRuleRecord; | import org.apache.poi.hssf.record.CFRuleRecord; | ||||
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; | import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; | ||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
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.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; | ||||
CFRuleRecord rr = CFRuleRecord.create(_sheet, formula); | CFRuleRecord rr = CFRuleRecord.create(_sheet, formula); | ||||
return new HSSFConditionalFormattingRule(wb, rr); | 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 | * Adds a copy of HSSFConditionalFormatting object to the sheet |
import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting; | import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting; | ||||
import org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule; | import org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule; | ||||
import org.apache.poi.ss.ITestDataProvider; | import org.apache.poi.ss.ITestDataProvider; | ||||
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet; | |||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
/** | /** | ||||
Sheet s = wb.getSheet("CF"); | Sheet s = wb.getSheet("CF"); | ||||
ConditionalFormatting cf = null; | ConditionalFormatting cf = null; | ||||
ConditionalFormattingRule cr = null; | ConditionalFormattingRule cr = null; | ||||
IconMultiStateFormatting icon = null; | |||||
// Sanity check data | // Sanity check data | ||||
assertEquals("Values", s.getRow(0).getCell(0).toString()); | assertEquals("Values", s.getRow(0).getCell(0).toString()); | ||||
// Colours R->G - Column F | // Colours R->G - Column F | ||||
// Colours BWR - Column G | // Colours BWR - Column G | ||||
// Icons : Default - Column H | // 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 signs - Column I | ||||
// Icons : 3 traffic lights 2 - Column J | // Icons : 3 traffic lights 2 - Column J | ||||
// Icons : 4 traffic lights - Column K | // Icons : 4 traffic lights - Column K | ||||
assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight()); | assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight()); | ||||
} | } | ||||
public void testCreateIconFormatting() { | |||||
// TODO Implement for XSSF, then test here | |||||
} | |||||
public void testBug55380() { | public void testBug55380() { | ||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); |