/// <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));
        }
Example #2
0
        public void TestCFRecordsAggregate1()
        {
            HSSFWorkbook  workbook = new HSSFWorkbook();
            HSSFSheet     sheet    = (HSSFSheet)workbook.CreateSheet();
            List <Record> recs     = new List <Record>();
            CFHeaderBase  header   = new CFHeaderRecord();
            CFRuleBase    rule1    = CFRuleRecord.Create(sheet, "7");
            CFRuleBase    rule2    = CFRuleRecord.Create(sheet, (byte)ComparisonOperator.Between, "2", "5");
            CFRuleBase    rule3    = CFRuleRecord.Create(sheet, (byte)ComparisonOperator.GreaterThanOrEqual, "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 = CFRecordsAggregate.CreateCFAggregate(new RecordStream(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];
            Assert.IsNotNull(rule1);
            rule2 = (CFRuleRecord)recs[2];
            Assert.IsNotNull(rule2);
            rule3 = (CFRuleRecord)recs[3];
            Assert.IsNotNull(rule3);
            cellRanges = header.CellRanges;

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

            record = CFRecordsAggregate.CreateCFAggregate(new RecordStream(recs, 0));

            record = record.CloneCFAggregate();

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

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

            Assert.AreEqual(2, cellRanges.Length);
            Assert.AreEqual(3, header.NumberOfConditionalFormats);
            Assert.IsFalse(header.NeedRecalculation);
        }
Example #3
0
        private void GetChildren()
        {
            RecordAggregate record = (RecordAggregate)this.Record;

            if (record is RowRecordsAggregate)
            {
                IEnumerator recordenum = ((RowRecordsAggregate)record).GetEnumerator();
                while (recordenum.MoveNext())
                {
                    if (recordenum.Current is RowRecord)
                    {
                        this.Nodes.Add(new RecordTreeNode((RowRecord)recordenum.Current));
                    }
                }
                CellValueRecordInterface[] valrecs = ((RowRecordsAggregate)record).GetValueRecords();
                for (int j = 0; j < valrecs.Length; j++)
                {
                    CellValueRecordTreeNode cvrtn = new CellValueRecordTreeNode(valrecs[j]);
                    if (valrecs[j] is FormulaRecordAggregate)
                    {
                        FormulaRecordAggregate fra = ((FormulaRecordAggregate)valrecs[j]);
                        cvrtn.ImageKey = "Folder";
                        if (fra.FormulaRecord != null)
                        {
                            cvrtn.Nodes.Add(new RecordTreeNode(fra.FormulaRecord));
                        }
                        if (fra.StringRecord != null)
                        {
                            cvrtn.Nodes.Add(new RecordTreeNode(fra.StringRecord));
                        }
                    }
                    this.Nodes.Add(cvrtn);
                }
            }
            else if (record is ColumnInfoRecordsAggregate)
            {
                IEnumerator recordenum = ((ColumnInfoRecordsAggregate)record).GetEnumerator();
                while (recordenum.MoveNext())
                {
                    if (recordenum.Current is ColumnInfoRecord)
                    {
                        this.Nodes.Add(new RecordTreeNode((ColumnInfoRecord)recordenum.Current));
                    }
                }
            }
            else if (record is PageSettingsBlock)
            {
                PageSettingsBlock psb = (PageSettingsBlock)record;
                MockRecordVisitor rv  = new MockRecordVisitor();
                psb.VisitContainedRecords(rv);
                foreach (Record rec in rv.Records)
                {
                    this.Nodes.Add(new RecordTreeNode(rec));
                }
            }
            else if (record is MergedCellsTable)
            {
                foreach (CellRangeAddress subRecord in ((MergedCellsTable)record).MergedRegions)
                {
                    this.Nodes.Add(new CellRangeAddressTreeNode(subRecord));
                }
            }
            else if (record is ConditionalFormattingTable)
            {
                ConditionalFormattingTable cft = (ConditionalFormattingTable)record;
                for (int j = 0; j < cft.Count; j++)
                {
                    CFRecordsAggregate cfra = cft.Get(j);

                    AbstractRecordTreeNode headernode = new RecordTreeNode(cfra.Header);
                    this.Nodes.Add(headernode);
                    for (int k = 0; k < cfra.NumberOfRules; k++)
                    {
                        this.Nodes.Add(new RecordTreeNode(cfra.GetRule(k)));
                    }
                }
            }
            else if (record is WorksheetProtectionBlock)
            {
                WorksheetProtectionBlock wpb = (WorksheetProtectionBlock)record;
                MockRecordVisitor        rv  = new MockRecordVisitor();
                wpb.VisitContainedRecords(rv);
                foreach (Record rec in rv.Records)
                {
                    this.Nodes.Add(new RecordTreeNode(rec));
                }
            }
        }
Example #4
0
        /// <summary>
        /// Gets the Conditional Formatting rule at position idx
        /// </summary>
        /// <param name="idx">The index.</param>
        /// <returns></returns>
        public IConditionalFormattingRule GetRule(int idx)
        {
            CFRuleBase ruleRecord = cfAggregate.GetRule(idx);

            return(new HSSFConditionalFormattingRule(sheet, ruleRecord));
        }