Esempio n. 1
0
        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);
        }
Esempio n. 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");
            }
        }
Esempio n. 3
0
        public override Object Clone()
        {
            CFRuleRecord rec = new CFRuleRecord(ConditionType, ComparisonOperation);

            base.CopyTo(rec);
            return(rec);
        }
 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 ArrayList(3);
     for (int i = 0; i < pRules.Length; i++)
     {
         rules.Add(pRules[i]);
     }
 }
Esempio n. 5
0
 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_97_2003_CONDTIONAL_FORMAT_RULES)
     {
         Console.WriteLine("Excel versions before 2007 require that "
             + "No more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
             + " rules may be specified, " + pRules.Length + " were found,"
             + " this file will cause problems with old Excel versions");
     }
     header = pHeader;
     rules = new List<CFRuleRecord>(3);
     for (int i = 0; i < pRules.Length; i++)
     {
         rules.Add(pRules[i]);
     }
 }
Esempio n. 6
0
 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, HSSFConditionalFormattingRule[] 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] = cfRules[i].CfRuleRecord;
            }
            CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
            return _conditionalFormattingTable.Add(cfra);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public CFRecordsAggregate(CellRangeAddress[] regions, CFRuleRecord[] rules)
            : this(new CFHeaderRecord(regions, rules.Length), rules)
        {

        }
Esempio n. 10
0
 public HSSFBorderFormatting(CFRuleRecord cfRuleRecord)
 {
     this.cfRuleRecord = cfRuleRecord;
     this.borderFormatting = cfRuleRecord.BorderFormatting;
 }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
 }
 public HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord)
 {
     workbook = pWorkbook;
     cfRuleRecord = pRuleRecord;
 }
Esempio n. 15
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);
	    }
Esempio n. 16
0
 public void SetRule(int idx, CFRuleRecord r)
 {
     CheckRuleIndex(idx);
     rules[idx] = r;
 }
 /// <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;
 }
Esempio n. 18
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);
 }
Esempio n. 19
0
        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;
        }
Esempio n. 20
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);
	    }