#58130 more progress towards supporting other CF types
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691472 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8b9fbc2fa
commit
0cde71224d
@ -20,11 +20,13 @@ package org.apache.poi.hssf.record;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.hssf.record.cf.IconMultiStateFormatting;
|
||||
import org.apache.poi.hssf.record.cf.Threshold;
|
||||
import org.apache.poi.hssf.record.common.FtrHeader;
|
||||
import org.apache.poi.hssf.record.common.FutureRecord;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
@ -116,6 +118,22 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
||||
return new CFRule12Record(CONDITION_TYPE_CELL_VALUE_IS, comparisonOperation,
|
||||
formula1, formula2, formula3);
|
||||
}
|
||||
/**
|
||||
* Creates a new Icon Set / Multi-State formatting
|
||||
*/
|
||||
public static CFRule12Record create(HSSFSheet sheet, IconSet iconSet) {
|
||||
Threshold[] ts = new Threshold[iconSet.num];
|
||||
for (int i=0; i<ts.length; i++) {
|
||||
ts[i] = new Threshold();
|
||||
}
|
||||
|
||||
CFRule12Record r = new CFRule12Record(CONDITION_TYPE_COLOR_SCALE,
|
||||
ComparisonOperator.NO_COMPARISON);
|
||||
r.getMultiStateFormatting().setIconSet(iconSet);
|
||||
r.getMultiStateFormatting().setThresholds(ts);
|
||||
return r;
|
||||
}
|
||||
// TODO Static creators for the other record types
|
||||
|
||||
public CFRule12Record(RecordInputStream in) {
|
||||
futureHeader = new FtrHeader(in);
|
||||
|
@ -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;
|
||||
|
||||
@ -90,21 +92,23 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||
}
|
||||
|
||||
// TODO Support types beyond CELL_VALUE_IS and FORMULA
|
||||
|
||||
/**
|
||||
* A factory method allowing the creation of conditional formatting
|
||||
* rules using an Icon Set / Multi-State formatting/
|
||||
* rules using an Icon Set / Multi-State formatting.
|
||||
* The thresholds for it will be created, but will be empty
|
||||
* and require configuring with
|
||||
* {@link HSSFConditionalFormattingRule#getMultiStateFormatting()}
|
||||
* then
|
||||
* {@link HSSFIconMultiStateFormatting#getThresholds()}
|
||||
*/
|
||||
// TODO Implement
|
||||
/*
|
||||
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
||||
IconSet iconSet) { // TODO Multi-State data for it
|
||||
IconSet iconSet) {
|
||||
CFRule12Record rr = CFRule12Record.create(_sheet, iconSet);
|
||||
return new HSSFConditionalFormattingRule(_sheet, rr);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO Support types beyond CELL_VALUE_IS and FORMULA and ICONs
|
||||
|
||||
/**
|
||||
* Adds a copy of HSSFConditionalFormatting object to the sheet
|
||||
* <p>This method could be used to copy HSSFConditionalFormatting object
|
||||
|
@ -74,10 +74,15 @@ public interface ConditionalFormattingRule {
|
||||
PatternFormatting createPatternFormatting();
|
||||
|
||||
/**
|
||||
* @return - pattern formatting object if defined, <code>null</code> otherwise
|
||||
* @return - pattern formatting object if defined, <code>null</code> otherwise
|
||||
*/
|
||||
PatternFormatting getPatternFormatting();
|
||||
|
||||
/**
|
||||
* @return - icon / multi-state formatting object if defined, <code>null</code> otherwise
|
||||
*/
|
||||
IconMultiStateFormatting getMultiStateFormatting();
|
||||
|
||||
/**
|
||||
* Type of conditional formatting rule.
|
||||
* <p>
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
@ -135,6 +136,18 @@ public interface SheetConditionalFormatting {
|
||||
*/
|
||||
ConditionalFormattingRule createConditionalFormattingRule(String formula);
|
||||
|
||||
/**
|
||||
* Create an Icon Set / Multi-State conditional formatting rule.
|
||||
* <p>The thresholds for it will be created, but will be empty
|
||||
* and require configuring with
|
||||
* {@link ConditionalFormattingRule#getMultiStateFormatting()}
|
||||
* then
|
||||
* {@link IconMultiStateFormatting#getThresholds()}
|
||||
*/
|
||||
ConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet);
|
||||
|
||||
// TODO Support types beyond CELL_VALUE_IS and FORMULA and ICONs
|
||||
|
||||
/**
|
||||
* Gets Conditional Formatting object at a particular index
|
||||
*
|
||||
|
@ -178,6 +178,14 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
|
||||
|
||||
return new XSSFPatternFormatting(dxf.getFill());
|
||||
}
|
||||
|
||||
|
||||
public IconMultiStateFormatting createMultiStateFormatting() {
|
||||
throw new IllegalArgumentException("Not implemented yet"); // TODO
|
||||
}
|
||||
public IconMultiStateFormatting getMultiStateFormatting() {
|
||||
throw new IllegalArgumentException("Not implemented yet"); // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of conditional formatting rule.
|
||||
|
@ -27,10 +27,13 @@ import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.ComparisonOperator;
|
||||
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;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColorScale;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
|
||||
@ -118,6 +121,32 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method allowing the creation of conditional formatting
|
||||
* rules using an Icon Set / Multi-State formatting.
|
||||
* The thresholds for it will be created, but will be empty
|
||||
* and require configuring with
|
||||
* {@link XSSFConditionalFormattingRule#getMultiStateFormatting()}
|
||||
* then
|
||||
* {@link XSSFIconMultiStateFormatting#getThresholds()}
|
||||
*/
|
||||
public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) {
|
||||
XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);
|
||||
CTCfRule cfRule = rule.getCTCfRule();
|
||||
cfRule.setType(STCfType.COLOR_SCALE);
|
||||
|
||||
CTIconSet icons = cfRule.addNewIconSet();
|
||||
if (iconSet.name != null) {
|
||||
// TODO Map to the enum
|
||||
// icons.setIconSet();
|
||||
}
|
||||
// TODO Add cfvos
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
// TODO Support types beyond CELL_VALUE_IS and FORMULA and ICONs
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) {
|
||||
if (regions == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user