mirror of https://github.com/apache/poi.git
Update objects / method signatures for the new CF Thresholds, to better match what the other CF bits expose where
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691452 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d18aec0795
commit
15adfb4e64
|
@ -425,7 +425,7 @@ public abstract class CFRuleBase extends StandardRecord {
|
||||||
*
|
*
|
||||||
* @return <code>null</code> if <tt>formula</tt> was null.
|
* @return <code>null</code> if <tt>formula</tt> was null.
|
||||||
*/
|
*/
|
||||||
protected static Ptg[] parseFormula(String formula, HSSFSheet sheet) {
|
public static Ptg[] parseFormula(String formula, HSSFSheet sheet) {
|
||||||
if(formula == null) {
|
if(formula == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.cf;
|
package org.apache.poi.hssf.record.cf;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.Formula;
|
import org.apache.poi.ss.formula.Formula;
|
||||||
|
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||||
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
|
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
|
||||||
import org.apache.poi.util.LittleEndianInput;
|
import org.apache.poi.util.LittleEndianInput;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
@ -42,19 +45,21 @@ public final class Threshold {
|
||||||
|
|
||||||
public Threshold() {
|
public Threshold() {
|
||||||
type = (byte)RangeType.NUMBER.id;
|
type = (byte)RangeType.NUMBER.id;
|
||||||
formula = null; // TODO SHould this be empty instead?
|
formula = Formula.create(null);
|
||||||
value = 0d;
|
value = 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates new Threshold */
|
/** Creates new Threshold */
|
||||||
public Threshold(LittleEndianInput in) {
|
public Threshold(LittleEndianInput in) {
|
||||||
type = in.readByte();
|
type = in.readByte();
|
||||||
short formuaLen = in.readShort();
|
short formulaLen = in.readShort();
|
||||||
if (formuaLen > 0) {
|
if (formulaLen > 0) {
|
||||||
formula = Formula.read(formuaLen, in);
|
formula = Formula.read(formulaLen, in);
|
||||||
|
} else {
|
||||||
|
formula = Formula.create(null);
|
||||||
}
|
}
|
||||||
// Value is only there for non-formula, non min/max thresholds
|
// Value is only there for non-formula, non min/max thresholds
|
||||||
if (formula == null && type != RangeType.MIN.id &&
|
if (formulaLen == 0 && type != RangeType.MIN.id &&
|
||||||
type != RangeType.MAX.id) {
|
type != RangeType.MAX.id) {
|
||||||
value = in.readDouble();
|
value = in.readDouble();
|
||||||
}
|
}
|
||||||
|
@ -70,11 +75,14 @@ public final class Threshold {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Formula getFormula() {
|
protected Formula getFormula() {
|
||||||
return formula;
|
return formula;
|
||||||
}
|
}
|
||||||
public void setFormula(Formula formula) {
|
public Ptg[] getParsedExpression() {
|
||||||
this.formula = formula;
|
return formula.getTokens();
|
||||||
|
}
|
||||||
|
public void setParsedExpression(Ptg[] ptgs) {
|
||||||
|
formula = Formula.create(ptgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getValue() {
|
public Double getValue() {
|
||||||
|
@ -92,12 +100,7 @@ public final class Threshold {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDataLength() {
|
public int getDataLength() {
|
||||||
int len = 1;
|
int len = 1 + formula.getEncodedSize();
|
||||||
if (formula != null) {
|
|
||||||
len += formula.getEncodedSize();
|
|
||||||
} else {
|
|
||||||
len += 2;
|
|
||||||
}
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
len += 8;
|
len += 8;
|
||||||
}
|
}
|
||||||
|
@ -105,13 +108,11 @@ public final class Threshold {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append(" [CF Threshold]\n");
|
buffer.append(" [CF Threshold]\n");
|
||||||
buffer.append(" .type = ").append(Integer.toHexString(type)).append("\n");
|
buffer.append(" .type = ").append(Integer.toHexString(type)).append("\n");
|
||||||
// TODO Output the formula better
|
buffer.append(" .formula = ").append(Arrays.toString(formula.getTokens())).append("\n");
|
||||||
buffer.append(" .formula = ").append(formula).append("\n");
|
|
||||||
buffer.append(" .value = ").append(value).append("\n");
|
buffer.append(" .value = ").append(value).append("\n");
|
||||||
buffer.append(" [/CF Threshold]\n");
|
buffer.append(" [/CF Threshold]\n");
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
|
|
@ -74,20 +74,20 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
* </PRE>
|
* </PRE>
|
||||||
*/
|
*/
|
||||||
public final class HSSFConditionalFormatting implements ConditionalFormatting {
|
public final class HSSFConditionalFormatting implements ConditionalFormatting {
|
||||||
private final HSSFWorkbook _workbook;
|
private final HSSFSheet sheet;
|
||||||
private final CFRecordsAggregate cfAggregate;
|
private final CFRecordsAggregate cfAggregate;
|
||||||
|
|
||||||
// TODO Should this be assigning unique IDs to the rules
|
// TODO Should this be assigning unique IDs to the rules
|
||||||
// as they get added to the file?
|
// as they get added to the file?
|
||||||
|
|
||||||
HSSFConditionalFormatting(HSSFWorkbook workbook, CFRecordsAggregate cfAggregate) {
|
HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) {
|
||||||
if(workbook == null) {
|
if(sheet == null) {
|
||||||
throw new IllegalArgumentException("workbook must not be null");
|
throw new IllegalArgumentException("sheet must not be null");
|
||||||
}
|
}
|
||||||
if(cfAggregate == null) {
|
if(cfAggregate == null) {
|
||||||
throw new IllegalArgumentException("cfAggregate must not be null");
|
throw new IllegalArgumentException("cfAggregate must not be null");
|
||||||
}
|
}
|
||||||
_workbook = workbook;
|
this.sheet = sheet;
|
||||||
this.cfAggregate = cfAggregate;
|
this.cfAggregate = cfAggregate;
|
||||||
}
|
}
|
||||||
CFRecordsAggregate getCFRecordsAggregate() {
|
CFRecordsAggregate getCFRecordsAggregate() {
|
||||||
|
@ -143,7 +143,7 @@ public final class HSSFConditionalFormatting implements ConditionalFormatting {
|
||||||
*/
|
*/
|
||||||
public HSSFConditionalFormattingRule getRule(int idx) {
|
public HSSFConditionalFormattingRule getRule(int idx) {
|
||||||
CFRuleBase ruleRecord = cfAggregate.getRule(idx);
|
CFRuleBase ruleRecord = cfAggregate.getRule(idx);
|
||||||
return new HSSFConditionalFormattingRule(_workbook, ruleRecord);
|
return new HSSFConditionalFormattingRule(sheet, ruleRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,15 +41,17 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||||
|
|
||||||
private final CFRuleBase cfRuleRecord;
|
private final CFRuleBase cfRuleRecord;
|
||||||
private final HSSFWorkbook workbook;
|
private final HSSFWorkbook workbook;
|
||||||
|
private final HSSFSheet sheet;
|
||||||
|
|
||||||
HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleBase pRuleRecord) {
|
HSSFConditionalFormattingRule(HSSFSheet pSheet, CFRuleBase pRuleRecord) {
|
||||||
if (pWorkbook == null) {
|
if (pSheet == null) {
|
||||||
throw new IllegalArgumentException("pWorkbook must not be null");
|
throw new IllegalArgumentException("pSheet must not be null");
|
||||||
}
|
}
|
||||||
if (pRuleRecord == null) {
|
if (pRuleRecord == null) {
|
||||||
throw new IllegalArgumentException("pRuleRecord must not be null");
|
throw new IllegalArgumentException("pRuleRecord must not be null");
|
||||||
}
|
}
|
||||||
workbook = pWorkbook;
|
sheet = pSheet;
|
||||||
|
workbook = pSheet.getWorkbook();
|
||||||
cfRuleRecord = pRuleRecord;
|
cfRuleRecord = pRuleRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,12 +181,12 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||||
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting();
|
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting();
|
||||||
if (iconFormatting != null)
|
if (iconFormatting != null)
|
||||||
{
|
{
|
||||||
return new HSSFIconMultiStateFormatting(cfRule12Record);
|
return new HSSFIconMultiStateFormatting(cfRule12Record, sheet);
|
||||||
}
|
}
|
||||||
else if( create )
|
else if( create )
|
||||||
{
|
{
|
||||||
iconFormatting = cfRule12Record.createMultiStateFormatting();
|
iconFormatting = cfRule12Record.createMultiStateFormatting();
|
||||||
return new HSSFIconMultiStateFormatting(cfRule12Record);
|
return new HSSFIconMultiStateFormatting(cfRule12Record, sheet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -245,7 +247,10 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toFormulaString(Ptg[] parsedExpression) {
|
protected String toFormulaString(Ptg[] parsedExpression) {
|
||||||
|
return toFormulaString(parsedExpression, workbook);
|
||||||
|
}
|
||||||
|
protected static String toFormulaString(Ptg[] parsedExpression, HSSFWorkbook workbook) {
|
||||||
if(parsedExpression == null || parsedExpression.length == 0) {
|
if(parsedExpression == null || parsedExpression.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
|
import static org.apache.poi.hssf.record.CFRuleBase.parseFormula;
|
||||||
|
import static org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule.toFormulaString;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.cf.Threshold;
|
import org.apache.poi.hssf.record.cf.Threshold;
|
||||||
import org.apache.poi.ss.formula.Formula;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level representation for Icon / Multi-State / Databar /
|
* High level representation for Icon / Multi-State / Databar /
|
||||||
|
@ -26,9 +28,13 @@ import org.apache.poi.ss.formula.Formula;
|
||||||
*/
|
*/
|
||||||
public final class HSSFConditionalFormattingThreshold implements org.apache.poi.ss.usermodel.ConditionalFormattingThreshold {
|
public final class HSSFConditionalFormattingThreshold implements org.apache.poi.ss.usermodel.ConditionalFormattingThreshold {
|
||||||
private final Threshold threshold;
|
private final Threshold threshold;
|
||||||
|
private final HSSFSheet sheet;
|
||||||
|
private final HSSFWorkbook workbook;
|
||||||
|
|
||||||
protected HSSFConditionalFormattingThreshold(Threshold threshold) {
|
protected HSSFConditionalFormattingThreshold(Threshold threshold, HSSFSheet sheet) {
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
|
this.sheet = sheet;
|
||||||
|
this.workbook = sheet.getWorkbook();
|
||||||
}
|
}
|
||||||
protected Threshold getThreshold() {
|
protected Threshold getThreshold() {
|
||||||
return threshold;
|
return threshold;
|
||||||
|
@ -41,11 +47,11 @@ public final class HSSFConditionalFormattingThreshold implements org.apache.poi.
|
||||||
threshold.setType((byte)type.id);
|
threshold.setType((byte)type.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Formula getFormula() {
|
public String getFormula() {
|
||||||
return threshold.getFormula();
|
return toFormulaString(threshold.getParsedExpression(), workbook);
|
||||||
}
|
}
|
||||||
public void setFormula(Formula formula) {
|
public void setFormula(String formula) {
|
||||||
threshold.setFormula(formula);
|
threshold.setParsedExpression(parseFormula(formula, sheet));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getValue() {
|
public Double getValue() {
|
||||||
|
|
|
@ -27,10 +27,12 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold;
|
||||||
* component of Conditional Formatting settings
|
* component of Conditional Formatting settings
|
||||||
*/
|
*/
|
||||||
public final class HSSFIconMultiStateFormatting implements org.apache.poi.ss.usermodel.IconMultiStateFormatting {
|
public final class HSSFIconMultiStateFormatting implements org.apache.poi.ss.usermodel.IconMultiStateFormatting {
|
||||||
|
private final HSSFSheet sheet;
|
||||||
private final CFRule12Record cfRule12Record;
|
private final CFRule12Record cfRule12Record;
|
||||||
private final IconMultiStateFormatting iconFormatting;
|
private final IconMultiStateFormatting iconFormatting;
|
||||||
|
|
||||||
protected HSSFIconMultiStateFormatting(CFRule12Record cfRule12Record) {
|
protected HSSFIconMultiStateFormatting(CFRule12Record cfRule12Record, HSSFSheet sheet) {
|
||||||
|
this.sheet = sheet;
|
||||||
this.cfRule12Record = cfRule12Record;
|
this.cfRule12Record = cfRule12Record;
|
||||||
this.iconFormatting = this.cfRule12Record.getMultiStateFormatting();
|
this.iconFormatting = this.cfRule12Record.getMultiStateFormatting();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +62,7 @@ public final class HSSFIconMultiStateFormatting implements org.apache.poi.ss.use
|
||||||
Threshold[] t = iconFormatting.getThresholds();
|
Threshold[] t = iconFormatting.getThresholds();
|
||||||
HSSFConditionalFormattingThreshold[] ht = new HSSFConditionalFormattingThreshold[t.length];
|
HSSFConditionalFormattingThreshold[] ht = new HSSFConditionalFormattingThreshold[t.length];
|
||||||
for (int i=0; i<t.length; i++) {
|
for (int i=0; i<t.length; i++) {
|
||||||
ht[i] = new HSSFConditionalFormattingThreshold(t[i]);
|
ht[i] = new HSSFConditionalFormattingThreshold(t[i], sheet);
|
||||||
}
|
}
|
||||||
return ht;
|
return ht;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
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;
|
||||||
|
@ -25,7 +24,6 @@ import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -69,19 +67,15 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||||
byte comparisonOperation,
|
byte comparisonOperation,
|
||||||
String formula1,
|
String formula1,
|
||||||
String formula2) {
|
String formula2) {
|
||||||
|
|
||||||
HSSFWorkbook wb = _sheet.getWorkbook();
|
|
||||||
CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
|
CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
|
||||||
return new HSSFConditionalFormattingRule(wb, rr);
|
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
||||||
byte comparisonOperation,
|
byte comparisonOperation,
|
||||||
String formula1) {
|
String formula1) {
|
||||||
|
|
||||||
HSSFWorkbook wb = _sheet.getWorkbook();
|
|
||||||
CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, null);
|
CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, null);
|
||||||
return new HSSFConditionalFormattingRule(wb, rr);
|
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,9 +86,8 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||||
* @param formula - formula for the valued, compared with the cell
|
* @param formula - formula for the valued, compared with the cell
|
||||||
*/
|
*/
|
||||||
public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
|
public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
|
||||||
HSSFWorkbook wb = _sheet.getWorkbook();
|
|
||||||
CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
|
CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
|
||||||
return new HSSFConditionalFormattingRule(wb, rr);
|
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Support types beyond CELL_VALUE_IS and FORMULA
|
// TODO Support types beyond CELL_VALUE_IS and FORMULA
|
||||||
|
@ -107,9 +100,8 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||||
/*
|
/*
|
||||||
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
||||||
IconSet iconSet) { // TODO Multi-State data for it
|
IconSet iconSet) { // TODO Multi-State data for it
|
||||||
HSSFWorkbook wb = _sheet.getWorkbook();
|
|
||||||
CFRule12Record rr = CFRule12Record.create(_sheet, iconSet);
|
CFRule12Record rr = CFRule12Record.create(_sheet, iconSet);
|
||||||
return new HSSFConditionalFormattingRule(wb, rr);
|
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -232,7 +224,7 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||||
if (cf == null) {
|
if (cf == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf);
|
return new HSSFConditionalFormatting(_sheet, cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.Formula;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Threshold / CFVO / Conditional Formatting Value Object.
|
* The Threshold / CFVO / Conditional Formatting Value Object.
|
||||||
|
@ -79,13 +78,13 @@ public interface ConditionalFormattingThreshold {
|
||||||
* Formula to use to calculate the threshold,
|
* Formula to use to calculate the threshold,
|
||||||
* or <code>null</code> if no formula
|
* or <code>null</code> if no formula
|
||||||
*/
|
*/
|
||||||
Formula getFormula();
|
String getFormula();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the formula used to calculate the threshold,
|
* Sets the formula used to calculate the threshold,
|
||||||
* or unsets it if <code>null</code> is given.
|
* or unsets it if <code>null</code> is given.
|
||||||
*/
|
*/
|
||||||
void setFormula(Formula formula);
|
void setFormula(String formula);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value used for the threshold, or
|
* Gets the value used for the threshold, or
|
||||||
|
|
Loading…
Reference in New Issue