private CFRecordsAggregate(CFHeaderRecord pHeader, CFRuleRecord[] pRules)
 {
     if (pHeader == null)
     {
         throw new ArgumentException("header must not be null");
     }
     if (pRules == null)
     {
         throw new ArgumentException("rules must not be null");
     }
     if (pRules.Length > MAX_CONDTIONAL_FORMAT_RULES)
     {
         throw new ArgumentException("No more than "
                 + MAX_CONDTIONAL_FORMAT_RULES + " rules may be specified");
     }
     header = pHeader;
     rules = new List<CFRuleRecord>(3);
     for (int i = 0; i < pRules.Length; i++)
     {
         rules.Add(pRules[i]);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFPatternFormatting"/> class.
 /// </summary>
 /// <param name="cfRuleRecord">The cf rule record.</param>
 public HSSFPatternFormatting(CFRuleRecord cfRuleRecord)
 {
     this.cfRuleRecord = cfRuleRecord;
     this.patternFormatting = cfRuleRecord.PatternFormatting;
 }
 public HSSFBorderFormatting(CFRuleRecord cfRuleRecord)
 {
     this.cfRuleRecord = cfRuleRecord;
     this.borderFormatting = cfRuleRecord.BorderFormatting;
 }
        /// <summary>
        /// Create CFRecordsAggregate from a list of CF Records
        /// </summary>
        /// <param name="rs">list of Record objects</param>
        public static CFRecordsAggregate CreateCFAggregate(RecordStream rs)
        {
            Record rec = rs.GetNext();
            if (rec.Sid != CFHeaderRecord.sid)
            {
                throw new InvalidOperationException("next record sid was " + rec.Sid
                        + " instead of " + CFHeaderRecord.sid + " as expected");
            }

            CFHeaderRecord header = (CFHeaderRecord)rec;
            int nRules = header.NumberOfConditionalFormats;

            CFRuleRecord[] rules = new CFRuleRecord[nRules];
            for (int i = 0; i < rules.Length; i++)
            {
                rules[i] = (CFRuleRecord)rs.GetNext();
            }

            return new CFRecordsAggregate(header, rules);
        }
        public CFRecordsAggregate(CellRangeAddress[] regions, CFRuleRecord[] rules)
            : this(new CFHeaderRecord(regions, rules.Length), rules)
        {

        }
 public void AddRule(CFRuleRecord r)
 {
     if (rules.Count >= MAX_CONDTIONAL_FORMAT_RULES)
     {
         throw new InvalidOperationException("Cannot have more than "
                 + MAX_CONDTIONAL_FORMAT_RULES + " conditional format rules");
     }
     rules.Add(r);
     header.NumberOfConditionalFormats = (rules.Count);
 }
        /// <summary>
        /// Create a deep Clone of the record
        /// </summary>
        public CFRecordsAggregate CloneCFAggregate()
        {

            CFRuleRecord[] newRecs = new CFRuleRecord[rules.Count];
            for (int i = 0; i < newRecs.Length; i++)
            {
                newRecs[i] = (CFRuleRecord)GetRule(i).Clone();
            }
            return new CFRecordsAggregate((CFHeaderRecord)header.Clone(), newRecs);
        }
 public void SetRule(int idx, CFRuleRecord r)
 {
     CheckRuleIndex(idx);
     rules[idx] = r;
 }
        /// <summary>
        /// Create CFRecordsAggregate from a list of CF Records
        /// </summary>
        /// <param name="recs">list of Record objects</param>
        /// <param name="pOffset">position of CFHeaderRecord object in the list of Record objects</param>
        public static CFRecordsAggregate CreateCFAggregate(IList recs, int pOffset)
        {
            Record rec = (Record)recs[pOffset];
            if (rec.Sid != CFHeaderRecord.sid)
            {
                throw new InvalidOperationException("next record sid was " + rec.Sid
                        + " instead of " + CFHeaderRecord.sid + " as expected");
            }

            CFHeaderRecord header = (CFHeaderRecord)rec;
            int nRules = header.NumberOfConditionalFormats;

            CFRuleRecord[] rules = new CFRuleRecord[nRules];
            int offset = pOffset;
            int countFound = 0;
            while (countFound < rules.Length)
            {
                offset++;
                if (offset >= recs.Count)
                {
                    break;
                }
                rec = (Record)recs[offset];
                if (rec is CFRuleRecord)
                {
                    rules[countFound] = (CFRuleRecord)rec;
                    countFound++;
                }
                else
                {
                    break;
                }
            }

            if (countFound < nRules)
            { // TODO -(MAR-2008) can this ever happen? Write junit 

                //if (log.Check(POILogger.DEBUG))
                //{
                //    log.Log(POILogger.DEBUG, "Expected  " + nRules + " Conditional Formats, "
                //            + "but found " + countFound + " rules");
                //}
                header.NumberOfConditionalFormats = (nRules);
                CFRuleRecord[] lessRules = new CFRuleRecord[countFound];
                Array.Copy(rules, 0, lessRules, 0, countFound);
                rules = lessRules;
            }
            return new CFRecordsAggregate(header, rules);
        }
        public override Object Clone()
        {
            CFRuleRecord rec = new CFRuleRecord(field_1_condition_type, (ComparisonOperator)field_2_comparison_operator);
            rec.field_5_options = field_5_options;
            rec.field_6_not_used = field_6_not_used;
            if (ContainsFontFormattingBlock)
            {
                rec.fontFormatting = (FontFormatting)fontFormatting.Clone();
            }
            if (ContainsBorderFormattingBlock)
            {
                rec.borderFormatting = (BorderFormatting)borderFormatting.Clone();
            }
            if (ContainsPatternFormattingBlock)
            {
                rec.patternFormatting = (PatternFormatting)patternFormatting.Clone();
            }
            if (field_17_formula1 != null)
            {
                rec.field_17_formula1 = field_17_formula1.Copy();
            }
            if (field_18_formula2 != null)
            {
                rec.field_18_formula2 = field_18_formula2.Copy();
            }

            return rec;
        }
 public HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord)
 {
     workbook = pWorkbook;
     cfRuleRecord = pRuleRecord;
 }
 public HSSFFontFormatting(CFRuleRecord cfRuleRecord)
 {
     this.fontFormatting = cfRuleRecord.FontFormatting;
 }
        /// <summary>
        /// Allows to Add a new Conditional Formatting Set to the sheet.
        /// </summary>
        /// <param name="regions">list of rectangular regions to apply conditional formatting rules</param>
        /// <param name="cfRules">Set of up to three conditional formatting rules</param>
        /// <returns>index of the newly Created Conditional Formatting object</returns>
        public int AddConditionalFormatting(CellRangeAddress[] regions, IConditionalFormattingRule[] cfRules)
        {
            if (regions == null)
            {
                throw new ArgumentException("regions must not be null");
            }
            if (cfRules == null)
            {
                throw new ArgumentException("cfRules must not be null");
            }
            if (cfRules.Length == 0)
            {
                throw new ArgumentException("cfRules must not be empty");
            }
            if (cfRules.Length > 3)
            {
                throw new ArgumentException("Number of rules must not exceed 3");
            }

            CFRuleRecord[] rules = new CFRuleRecord[cfRules.Length];
            for (int i = 0; i != cfRules.Length; i++)
            {
                rules[i] = ((HSSFConditionalFormattingRule)cfRules[i]).CfRuleRecord;
            }
            CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
            return _conditionalFormattingTable.Add(cfra);
        }