Exemple #1
0
        /// <summary>
        /// A factory method allowing to Create a conditional formatting rule with a formula.
        /// The formatting rules are applied by Excel when the value of the formula not equal to 0.
        /// TODO - formulas containing cell references are currently not Parsed properly
        /// </summary>
        /// <param name="formula">formula for the valued, Compared with the cell</param>
        /// <returns></returns>
        public IConditionalFormattingRule CreateConditionalFormattingRule(String formula)
        {
            HSSFWorkbook wb = (HSSFWorkbook)_sheet.Workbook;
            CFRuleRecord rr = CFRuleRecord.Create(_sheet, formula);

            return(new HSSFConditionalFormattingRule(wb, rr));
        }
Exemple #2
0
        public void TestCreateCFRuleRecord()
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet    sheet    = (HSSFSheet)workbook.CreateSheet();
            CFRuleRecord record   = CFRuleRecord.Create(sheet, "7");

            TestCFRuleRecord1(record);

            // Serialize
            byte[] SerializedRecord = record.Serialize();

            // Strip header
            byte[] recordData = new byte[SerializedRecord.Length - 4];
            Array.Copy(SerializedRecord, 4, recordData, 0, recordData.Length);

            // DeSerialize
            record = new CFRuleRecord(TestcaseRecordInputStream.Create(CFRuleRecord.sid, recordData));

            // Serialize again
            byte[] output = record.Serialize();

            // Compare
            Assert.AreEqual(recordData.Length + 4, output.Length, "Output size"); //includes sid+recordlength

            for (int i = 0; i < recordData.Length; i++)
            {
                Assert.AreEqual(recordData[i], output[i + 4], "CFRuleRecord doesn't match");
            }
        }
        public void TestNRules()
        {
            HSSFWorkbook workbook = new HSSFWorkbook();

            CellRangeAddress[] cellRanges =
            {
                new CellRangeAddress(0, 1, 0, 0),
                new CellRangeAddress(0, 1, 2, 2),
            };
            CFRuleRecord[] rules =
            {
                CFRuleRecord.Create(workbook, "7"),
                CFRuleRecord.Create(workbook, ComparisonOperator.BETWEEN,"2",  "5"),
            };
            CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);

            byte[] serializedRecord = new byte[agg.RecordSize];
            agg.Serialize(0, serializedRecord);

            int nRules = NPOI.Util.LittleEndian.GetUShort(serializedRecord, 4);

            if (nRules == 0)
            {
                throw new AssertFailedException("Identified bug 45682 b");
            }
            Assert.AreEqual(rules.Length, nRules);
        }
Exemple #4
0
        /// <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));
        }
Exemple #5
0
        public void TestCantMixTypes()
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet    sheet    = workbook.CreateSheet() as HSSFSheet;

            CellRangeAddress[] cellRanges =
            {
                new CellRangeAddress(0, 1, 0, 0),
                new CellRangeAddress(0, 1, 2, 2),
            };
            CFRuleBase[] rules =
            {
                CFRuleRecord.Create(sheet,   "7"),
                CFRule12Record.Create(sheet, (byte)ComparisonOperator.Between,"2",  "5"),
            };
            try
            {
                new CFRecordsAggregate(cellRanges, rules);
                Assert.Fail("Shouldn't be able to mix between types");
            }
            catch (ArgumentException) { }

            rules = new CFRuleBase[] { CFRuleRecord.Create(sheet, "7") };
            CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);

            Assert.IsTrue(agg.Header.NeedRecalculation);

            try
            {
                agg.AddRule(CFRule12Record.Create(sheet, "7"));
                Assert.Fail("Shouldn't be able to mix between types");
            }
            catch (ArgumentException) { }
        }
Exemple #6
0
        public void TestConstructors()
        {
            IWorkbook workbook = new HSSFWorkbook();
            ISheet    sheet    = workbook.CreateSheet();

            CFRuleRecord rule1 = CFRuleRecord.Create((HSSFSheet)sheet, "7");

            Assert.AreEqual(CFRuleRecord.CONDITION_TYPE_FORMULA, rule1.ConditionType);
            Assert.AreEqual((byte)ComparisonOperator.NoComparison, rule1.ComparisonOperation);
            Assert.IsNotNull(rule1.ParsedExpression1);
            Assert.AreSame(Ptg.EMPTY_PTG_ARRAY, rule1.ParsedExpression2);

            CFRuleRecord rule2 = CFRuleRecord.Create((HSSFSheet)sheet, (byte)ComparisonOperator.Between, "2", "5");

            Assert.AreEqual(CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS, rule2.ConditionType);
            Assert.AreEqual((byte)ComparisonOperator.Between, rule2.ComparisonOperation);
            Assert.IsNotNull(rule2.ParsedExpression1);
            Assert.IsNotNull(rule2.ParsedExpression2);

            CFRuleRecord rule3 = CFRuleRecord.Create((HSSFSheet)sheet, (byte)ComparisonOperator.Equal, null, null);

            Assert.AreEqual(CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS, rule3.ConditionType);
            Assert.AreEqual((byte)ComparisonOperator.Equal, rule3.ComparisonOperation);
            Assert.AreSame(Ptg.EMPTY_PTG_ARRAY, rule3.ParsedExpression2);
            Assert.AreSame(Ptg.EMPTY_PTG_ARRAY, rule3.ParsedExpression2);
        }
Exemple #7
0
        private void TestCFRuleRecord1(CFRuleRecord record)
        {
            FontFormatting fontFormatting = new FontFormatting();

            TestFontFormattingAccessors(fontFormatting);
            Assert.IsFalse(record.ContainsFontFormattingBlock);
            record.FontFormatting = (fontFormatting);
            Assert.IsTrue(record.ContainsFontFormattingBlock);

            BorderFormatting borderFormatting = new BorderFormatting();

            TestBorderFormattingAccessors(borderFormatting);
            Assert.IsFalse(record.ContainsBorderFormattingBlock);
            record.BorderFormatting = (borderFormatting);
            Assert.IsTrue(record.ContainsBorderFormattingBlock);

            Assert.IsFalse(record.IsLeftBorderModified);
            record.IsLeftBorderModified = (true);
            Assert.IsTrue(record.IsLeftBorderModified);

            Assert.IsFalse(record.IsRightBorderModified);
            record.IsRightBorderModified = (true);
            Assert.IsTrue(record.IsRightBorderModified);

            Assert.IsFalse(record.IsTopBorderModified);
            record.IsTopBorderModified = (true);
            Assert.IsTrue(record.IsTopBorderModified);

            Assert.IsFalse(record.IsBottomBorderModified);
            record.IsBottomBorderModified = (true);
            Assert.IsTrue(record.IsBottomBorderModified);

            Assert.IsFalse(record.IsTopLeftBottomRightBorderModified);
            record.IsTopLeftBottomRightBorderModified = (true);
            Assert.IsTrue(record.IsTopLeftBottomRightBorderModified);

            Assert.IsFalse(record.IsBottomLeftTopRightBorderModified);
            record.IsBottomLeftTopRightBorderModified = (true);
            Assert.IsTrue(record.IsBottomLeftTopRightBorderModified);


            PatternFormatting patternFormatting = new PatternFormatting();

            TestPatternFormattingAccessors(patternFormatting);
            Assert.IsFalse(record.ContainsPatternFormattingBlock);
            record.PatternFormatting = (patternFormatting);
            Assert.IsTrue(record.ContainsPatternFormattingBlock);

            Assert.IsFalse(record.IsPatternBackgroundColorModified);
            record.IsPatternBackgroundColorModified = (true);
            Assert.IsTrue(record.IsPatternBackgroundColorModified);

            Assert.IsFalse(record.IsPatternColorModified);
            record.IsPatternColorModified = (true);
            Assert.IsTrue(record.IsPatternColorModified);

            Assert.IsFalse(record.IsPatternStyleModified);
            record.IsPatternStyleModified = (true);
            Assert.IsTrue(record.IsPatternStyleModified);
        }
Exemple #8
0
        public IConditionalFormattingRule CreateConditionalFormattingRule(
            ComparisonOperator comparisonOperation,
            String formula1)
        {
            CFRuleRecord rr = CFRuleRecord.Create(_sheet, (byte)comparisonOperation, formula1, null);

            return(new HSSFConditionalFormattingRule(_sheet, rr));
        }
        public IConditionalFormattingRule CreateConditionalFormattingRule(
            ComparisonOperator comparisonOperation,
            string formula1)
        {
            HSSFWorkbook wb = (HSSFWorkbook)_sheet.Workbook;
            CFRuleRecord rr = CFRuleRecord.Create(_sheet, (byte)comparisonOperation, formula1, null);

            return(new HSSFConditionalFormattingRule(wb, rr));
        }
Exemple #10
0
 /// <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));
 }
Exemple #11
0
 public override void VisitContainedRecords(RecordVisitor rv)
 {
     rv.VisitRecord(header);
     for (int i = 0; i < rules.Count; i++)
     {
         CFRuleRecord rule = (CFRuleRecord)rules[i];
         rv.VisitRecord(rule);
     }
 }
Exemple #12
0
 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>
        /// A factory method allowing to Create a conditional formatting rule
        /// with a cell comparison operator
        /// TODO - formulas containing cell references are currently not Parsed properly
        /// </summary>
        /// <param name="comparisonOperation">a constant value from HSSFConditionalFormattingRule.ComparisonOperator</param>
        /// <param name="formula1">formula for the valued, Compared with the cell</param>
        /// <param name="formula2">second formula (only used with HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN
        /// and HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN operations)</param>
        /// <returns></returns>
        public HSSFConditionalFormattingRule CreateConditionalFormattingRule(
            ComparisonOperator comparisonOperation,
            String formula1,
            String formula2)
        {
            HSSFWorkbook wb = _workbook;
            CFRuleRecord rr = CFRuleRecord.Create(wb, comparisonOperation, formula1, formula2);

            return(new HSSFConditionalFormattingRule(wb, rr));
        }
Exemple #14
0
 public void AddRule(CFRuleRecord r)
 {
     if (rules.Count >= MAX_97_2003_CONDTIONAL_FORMAT_RULES)
     {
         Console.WriteLine("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");
     }
     rules.Add(r);
     header.NumberOfConditionalFormats = (rules.Count);
 }
Exemple #15
0
        public void TestBug53691()
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet    sheet    = workbook.CreateSheet() as HSSFSheet;

            CFRuleRecord record = CFRuleRecord.Create(sheet, (byte)ComparisonOperator.Between, "2", "5") as CFRuleRecord;

            CFRuleRecord clone = (CFRuleRecord)record.Clone();

            byte[] SerializedRecord = record.Serialize();
            byte[] SerializedClone  = clone.Serialize();
            Assert.That(SerializedRecord, new EqualConstraint(SerializedClone));
        }
Exemple #16
0
        /**
         * @return <c>false</c> if this whole {@link CFHeaderRecord} / {@link CFRuleRecord}s should be deleted
         */
        public bool UpdateFormulasAfterCellShift(FormulaShifter shifter, int currentExternSheetIx)
        {
            CellRangeAddress[] cellRanges = header.CellRanges;
            bool      changed             = false;
            ArrayList temp = new ArrayList();

            for (int i = 0; i < cellRanges.Length; i++)
            {
                CellRangeAddress craOld = cellRanges[i];
                CellRangeAddress craNew = ShiftRange(shifter, craOld, currentExternSheetIx);
                if (craNew == null)
                {
                    changed = true;
                    continue;
                }
                temp.Add(craNew);
                if (craNew != craOld)
                {
                    changed = true;
                }
            }

            if (changed)
            {
                int nRanges = temp.Count;
                if (nRanges == 0)
                {
                    return(false);
                }
                CellRangeAddress[] newRanges = new CellRangeAddress[nRanges];
                newRanges         = (CellRangeAddress[])temp.ToArray(typeof(CellRangeAddress));
                header.CellRanges = (newRanges);
            }

            for (int i = 0; i < rules.Count; i++)
            {
                CFRuleRecord rule = (CFRuleRecord)rules[i];
                Ptg[]        ptgs;
                ptgs = rule.ParsedExpression1;
                if (ptgs != null && shifter.AdjustFormula(ptgs, currentExternSheetIx))
                {
                    rule.ParsedExpression1 = (ptgs);
                }
                ptgs = rule.ParsedExpression2;
                if (ptgs != null && shifter.AdjustFormula(ptgs, currentExternSheetIx))
                {
                    rule.ParsedExpression2 = (ptgs);
                }
            }
            return(true);
        }
Exemple #17
0
        /// <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));
        }
Exemple #18
0
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("[CF]\n");
            if (header != null)
            {
                buffer.Append(header.ToString());
            }
            for (int i = 0; i < rules.Count; i++)
            {
                CFRuleRecord cfRule = (CFRuleRecord)rules[i];
                if (cfRule != null)
                {
                    buffer.Append(cfRule.ToString());
                }
            }
            buffer.Append("[/CF]\n");
            return(buffer.ToString());
        }
Exemple #19
0
        private void TestCFRuleRecord1(CFRuleRecord record)
        {
            testCFRuleBase(record);


            Assert.IsFalse(record.IsLeftBorderModified);
            record.IsLeftBorderModified = (true);
            Assert.IsTrue(record.IsLeftBorderModified);

            Assert.IsFalse(record.IsRightBorderModified);
            record.IsRightBorderModified = (true);
            Assert.IsTrue(record.IsRightBorderModified);

            Assert.IsFalse(record.IsTopBorderModified);
            record.IsTopBorderModified = (true);
            Assert.IsTrue(record.IsTopBorderModified);

            Assert.IsFalse(record.IsBottomBorderModified);
            record.IsBottomBorderModified = (true);
            Assert.IsTrue(record.IsBottomBorderModified);

            Assert.IsFalse(record.IsTopLeftBottomRightBorderModified);
            record.IsTopLeftBottomRightBorderModified = (true);
            Assert.IsTrue(record.IsTopLeftBottomRightBorderModified);

            Assert.IsFalse(record.IsBottomLeftTopRightBorderModified);
            record.IsBottomLeftTopRightBorderModified = (true);
            Assert.IsTrue(record.IsBottomLeftTopRightBorderModified);

            Assert.IsFalse(record.IsPatternBackgroundColorModified);
            record.IsPatternBackgroundColorModified = (true);
            Assert.IsTrue(record.IsPatternBackgroundColorModified);

            Assert.IsFalse(record.IsPatternColorModified);
            record.IsPatternColorModified = (true);
            Assert.IsTrue(record.IsPatternColorModified);

            Assert.IsFalse(record.IsPatternStyleModified);
            record.IsPatternStyleModified = (true);
            Assert.IsTrue(record.IsPatternStyleModified);
        }
Exemple #20
0
        /// <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));
        }
Exemple #21
0
        public void TestReserializeRefNTokens()
        {
            RecordInputStream is1 = TestcaseRecordInputStream.Create(CFRuleRecord.sid, DATA_REFN);
            CFRuleRecord      rr  = new CFRuleRecord(is1);

            Ptg[] ptgs = rr.ParsedExpression1;
            Assert.AreEqual(3, ptgs.Length);
            if (ptgs[0] is RefPtg)
            {
                throw new AssertionException("Identified bug 45234");
            }
            Assert.AreEqual(typeof(RefNPtg), ptgs[0].GetType());
            RefNPtg refNPtg = (RefNPtg)ptgs[0];

            Assert.IsTrue(refNPtg.IsColRelative);
            Assert.IsTrue(refNPtg.IsRowRelative);

            byte[] data = rr.Serialize();

            TestcaseRecordInputStream.ConfirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data);
        }
Exemple #22
0
        public void TestWrite()
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            CFRuleRecord rr       = CFRuleRecord.Create(workbook, ComparisonOperator.BETWEEN, "5", "10");

            PatternFormatting patternFormatting = new PatternFormatting();

            patternFormatting.FillPattern = (PatternFormatting.BRICKS);
            rr.PatternFormatting          = (patternFormatting);

            byte[] data = rr.Serialize();
            Assert.AreEqual(26, data.Length);
            Assert.AreEqual(3, LittleEndian.GetShort(data, 6));
            Assert.AreEqual(3, LittleEndian.GetShort(data, 8));

            int flags = LittleEndian.GetInt(data, 10);

            Assert.AreEqual(0x00380000, flags & 0x00380000, "unused flags should be 111");
            Assert.AreEqual(0, flags & 0x03C00000, "undocumented flags should be 0000");        // Otherwise Excel s unhappy
            // check all remaining flag bits (some are not well understood yet)
            Assert.AreEqual(0x203FFFFF, flags);
        }
Exemple #23
0
        public void TestReserializeRefNTokens()
        {
            RecordInputStream is1 = TestcaseRecordInputStream.Create(CFRuleRecord.sid, DATA_REFN);
            CFRuleRecord      rr  = new CFRuleRecord(is1);

            Ptg[] ptgs = rr.ParsedExpression1;
            Assert.AreEqual(3, ptgs.Length);
            if (ptgs[0] is RefPtg)
            {
                throw new AssertFailedException("Identified bug 45234");
            }
            Assert.AreEqual(typeof(RefNPtg), ptgs[0].GetType());
            RefNPtg refNPtg = (RefNPtg)ptgs[0];

            Assert.IsTrue(refNPtg.IsColRelative);
            Assert.IsTrue(refNPtg.IsRowRelative);

            byte[] data = rr.Serialize();

            if (!CompareArrays(DATA_REFN, 0, data, 4, DATA_REFN.Length))
            {
                Assert.Fail("Did not re-serialize correctly");
            }
        }
Exemple #24
0
 public HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord)
 {
     workbook     = pWorkbook;
     cfRuleRecord = pRuleRecord;
 }
 public HSSFBorderFormatting(CFRuleRecord cfRuleRecord)
 {
     this.cfRuleRecord     = cfRuleRecord;
     this.borderFormatting = cfRuleRecord.BorderFormatting;
 }
Exemple #26
0
        /// <summary>
        /// A factory method allowing to Create a conditional formatting rule with a formula.
        /// The formatting rules are applied by Excel when the value of the formula not equal to 0.
        /// TODO - formulas containing cell references are currently not Parsed properly
        /// </summary>
        /// <param name="formula">formula for the valued, Compared with the cell</param>
        /// <returns></returns>
        public IConditionalFormattingRule CreateConditionalFormattingRule(String formula)
        {
            CFRuleRecord rr = CFRuleRecord.Create(_sheet, formula);

            return(new HSSFConditionalFormattingRule(_sheet, rr));
        }
        public void TestCFRecordsAggregate()
        {
            HSSFWorkbook   workbook = new HSSFWorkbook();
            IList          recs     = new ArrayList();
            CFHeaderRecord header   = new CFHeaderRecord();
            CFRuleRecord   rule1    = CFRuleRecord.Create(workbook, "7");
            CFRuleRecord   rule2    = CFRuleRecord.Create(workbook, ComparisonOperator.BETWEEN, "2", "5");
            CFRuleRecord   rule3    = CFRuleRecord.Create(workbook, ComparisonOperator.GE, "100", null);

            header.NumberOfConditionalFormats = (3);
            CellRangeAddress[] cellRanges =
            {
                new CellRangeAddress(0, 1, 0, 0),
                new CellRangeAddress(0, 1, 2, 2),
            };
            header.CellRanges = (cellRanges);
            recs.Add(header);
            recs.Add(rule1);
            recs.Add(rule2);
            recs.Add(rule3);
            CFRecordsAggregate record;

            record = CFRecordsAggregate.CreateCFAggregate(recs, 0);

            // Serialize
            byte [] serializedRecord = new byte[record.RecordSize];
            record.Serialize(0, serializedRecord);
            Stream in1 = new MemoryStream(serializedRecord);

            //Parse
            recs = RecordFactory.CreateRecords(in1);

            // Verify
            Assert.IsNotNull(recs);
            Assert.AreEqual(4, recs.Count);

            header     = (CFHeaderRecord)recs[0];
            rule1      = (CFRuleRecord)recs[1];
            rule2      = (CFRuleRecord)recs[2];
            rule3      = (CFRuleRecord)recs[3];
            cellRanges = header.CellRanges;

            Assert.AreEqual(2, cellRanges.Length);
            Assert.AreEqual(3, header.NumberOfConditionalFormats);

            record = CFRecordsAggregate.CreateCFAggregate(recs, 0);

            record = record.CloneCFAggregate();

            Assert.IsNotNull(record.Header);
            Assert.AreEqual(3, record.NumberOfRules);

            header     = record.Header;
            rule1      = record.GetRule(0);
            rule2      = record.GetRule(1);
            rule3      = record.GetRule(2);
            cellRanges = header.CellRanges;

            Assert.AreEqual(2, cellRanges.Length);
            Assert.AreEqual(3, header.NumberOfConditionalFormats);
        }
Exemple #28
0
 /// <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;
 }
        /// <summary>
        /// Gets the Conditional Formatting rule at position idx
        /// </summary>
        /// <param name="idx">The index.</param>
        /// <returns></returns>
        public IConditionalFormattingRule GetRule(int idx)
        {
            CFRuleRecord ruleRecord = cfAggregate.GetRule(idx);

            return(new HSSFConditionalFormattingRule(_workbook, ruleRecord));
        }
Exemple #30
0
 public void SetRule(int idx, CFRuleRecord r)
 {
     CheckRuleIndex(idx);
     rules[idx] = r;
 }