diff --git a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java index d6da4f686..c43e4f5ae 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java @@ -45,242 +45,237 @@ import org.apache.poi.util.POILogger; * not a file format one.
*/ public final class CFRecordsAggregate extends RecordAggregate { - /** Excel 97-2003 allows up to 3 conditional formating rules */ - private static final int MAX_97_2003_CONDTIONAL_FORMAT_RULES = 3; - private static final POILogger logger = POILogFactory.getLogger(CFRecordsAggregate.class); + /** Excel 97-2003 allows up to 3 conditional formating rules */ + private static final int MAX_97_2003_CONDTIONAL_FORMAT_RULES = 3; + private static final POILogger logger = POILogFactory.getLogger(CFRecordsAggregate.class); - private final CFHeaderBase header; + private final CFHeaderBase header; - /** List of CFRuleRecord objects */ - private final Listnull
.
- */
- public CFHeaderBase getHeader()
- {
- return header;
- }
-
- private void checkRuleIndex(int idx) {
- if(idx < 0 || idx >= rules.size()) {
- throw new IllegalArgumentException("Bad rule record index (" + idx
- + ") nRules=" + rules.size());
- }
- }
- private void checkRuleType(CFRuleBase r) {
- if (header instanceof CFHeaderRecord &&
- r instanceof CFRuleRecord) {
- return;
- }
+ /**
+ * Create a deep clone of the record
+ */
+ public CFRecordsAggregate cloneCFAggregate() {
+ CFRuleBase[] newRecs = new CFRuleBase[rules.size()];
+ for (int i = 0; i < newRecs.length; i++) {
+ newRecs[i] = (CFRuleRecord) getRule(i).clone();
+ }
+ return new CFRecordsAggregate((CFHeaderBase)header.clone(), newRecs);
+ }
+
+ /**
+ * @return the header. Never null
.
+ */
+ public CFHeaderBase getHeader() {
+ return header;
+ }
+
+ private void checkRuleIndex(int idx) {
+ if(idx < 0 || idx >= rules.size()) {
+ throw new IllegalArgumentException("Bad rule record index (" + idx
+ + ") nRules=" + rules.size());
+ }
+ }
+ private void checkRuleType(CFRuleBase r) {
+ if (header instanceof CFHeaderRecord &&
+ r instanceof CFRuleRecord) {
+ return;
+ }
if (header instanceof CFHeader12Record &&
r instanceof CFRule12Record) {
return;
}
throw new IllegalArgumentException("Header and Rule must both be CF or both be CF12, can't mix");
- }
-
- public CFRuleBase getRule(int idx) {
- checkRuleIndex(idx);
- return rules.get(idx);
- }
- public void setRule(int idx, CFRuleBase r) {
- if (r == null) {
- throw new IllegalArgumentException("r must not be null");
- }
- checkRuleIndex(idx);
- checkRuleType(r);
- rules.set(idx, r);
- }
- public void addRule(CFRuleBase r) {
- if (r == null) {
- throw new IllegalArgumentException("r must not be null");
- }
- if(rules.size() >= MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
- logger.log(POILogger.WARN, "Excel versions before 2007 cannot cope with"
- + " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
- + " - this file will cause problems with old Excel versions");
- }
+ }
+
+ public CFRuleBase getRule(int idx) {
+ checkRuleIndex(idx);
+ return rules.get(idx);
+ }
+ public void setRule(int idx, CFRuleBase r) {
+ if (r == null) {
+ throw new IllegalArgumentException("r must not be null");
+ }
+ checkRuleIndex(idx);
checkRuleType(r);
- rules.add(r);
- header.setNumberOfConditionalFormats(rules.size());
- }
- public int getNumberOfRules() {
- return rules.size();
- }
+ rules.set(idx, r);
+ }
+ public void addRule(CFRuleBase r) {
+ if (r == null) {
+ throw new IllegalArgumentException("r must not be null");
+ }
+ if(rules.size() >= MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
+ logger.log(POILogger.WARN, "Excel versions before 2007 cannot cope with"
+ + " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
+ + " - this file will cause problems with old Excel versions");
+ }
+ checkRuleType(r);
+ rules.add(r);
+ header.setNumberOfConditionalFormats(rules.size());
+ }
+ public int getNumberOfRules() {
+ return rules.size();
+ }
- /**
- * String representation of CFRecordsAggregate
- */
- public String toString()
- {
- StringBuffer buffer = new StringBuffer();
- String type = "CF";
- if (header instanceof CFHeader12Record) {
- type = "CF12";
- }
+ /**
+ * String representation of CFRecordsAggregate
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ String type = "CF";
+ if (header instanceof CFHeader12Record) {
+ type = "CF12";
+ }
- buffer.append("[").append(type).append("]\n");
- if( header != null )
- {
- buffer.append(header.toString());
- }
- for(int i=0; ifalse
if this whole {@link CFHeaderRecord} / {@link CFRuleRecord}s should be deleted
+ */
+ public boolean updateFormulasAfterCellShift(FormulaShifter shifter, int currentExternSheetIx) {
+ CellRangeAddress[] cellRanges = header.getCellRanges();
+ boolean changed = false;
+ List