aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-07-15 00:04:53 +0000
committerNick Burch <nick@apache.org>2015-07-15 00:04:53 +0000
commit7f8feae6f6293e51966331d0f42539a73bb4b59d (patch)
tree8014bc904d3c736b53935a16a4b3bcf3242d5ad3 /src/java
parent6b32c8f1f856be3d6b133a57e903451e6c36b031 (diff)
downloadpoi-7f8feae6f6293e51966331d0f42539a73bb4b59d.tar.gz
poi-7f8feae6f6293e51966331d0f42539a73bb4b59d.zip
Further HSSF support towards CF IconSets #58130
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691113 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/hssf/record/CFRule12Record.java8
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java43
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java16
3 files changed, 66 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/hssf/record/CFRule12Record.java b/src/java/org/apache/poi/hssf/record/CFRule12Record.java
index 2c684e3c17..230cb1dff4 100644
--- a/src/java/org/apache/poi/hssf/record/CFRule12Record.java
+++ b/src/java/org/apache/poi/hssf/record/CFRule12Record.java
@@ -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
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
index f3a81c0358..c36748e97c 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
@@ -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,8 +167,47 @@ 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
*/
public byte getConditionType() {
@@ -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);
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
index 1064467dbf..f0df8e5223 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
@@ -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