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) { } }
/// <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"); } CFRuleBase[] rules = new CFRuleBase[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)); }
/// <summary> /// Create a deep Clone of the record /// </summary> public CFRecordsAggregate CloneCFAggregate() { CFRuleBase[] newRecs = new CFRuleBase[rules.Count]; for (int i = 0; i < newRecs.Length; i++) { newRecs[i] = (CFRuleRecord)GetRule(i).Clone(); } return(new CFRecordsAggregate((CFHeaderBase)header.Clone(), newRecs)); }
public void AddRule(CFRuleBase 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"); } CheckRuleType(r); rules.Add(r); header.NumberOfConditionalFormats = (rules.Count); }
public HSSFConditionalFormattingRule(HSSFSheet pSheet, CFRuleBase pRuleRecord) { if (pSheet == null) { throw new ArgumentException("pSheet must not be null"); } if (pRuleRecord == null) { throw new ArgumentException("pRuleRecord must not be null"); } sheet = pSheet; workbook = pSheet.Workbook as HSSFWorkbook; cfRuleRecord = pRuleRecord; }
private void CheckRuleType(CFRuleBase r) { if (header is CFHeaderRecord && r is CFRuleRecord) { return; } if (header is CFHeader12Record && r is CFRule12Record) { return; } throw new ArgumentException("Header and Rule must both be CF or both be CF12, can't mix"); }
/// <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 && rec.Sid != CFHeader12Record.sid) { throw new InvalidOperationException("next record sid was " + rec.Sid + " instead of " + CFHeaderRecord.sid + " or " + CFHeader12Record.sid + " as expected"); } CFHeaderBase header = (CFHeaderBase)rec; int nRules = header.NumberOfConditionalFormats; CFRuleBase[] rules = new CFRuleBase[nRules]; for (int i = 0; i < rules.Length; i++) { rules[i] = (CFRuleBase)rs.GetNext(); } return(new CFRecordsAggregate(header, rules)); }
private void testCFRuleBase(CFRuleBase 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); PatternFormatting patternFormatting = new PatternFormatting(); TestPatternFormattingAccessors(patternFormatting); Assert.IsFalse(record.ContainsPatternFormattingBlock); record.PatternFormatting = (patternFormatting); Assert.IsTrue(record.ContainsPatternFormattingBlock); }
public HSSFBorderFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) { this.workbook = workbook; this.cfRuleRecord = cfRuleRecord; this.borderFormatting = cfRuleRecord.BorderFormatting; }
public void SetRule(int idx, CFRuleBase r) { CheckRuleIndex(idx); CheckRuleType(r); rules[idx] = r; }
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); }
public HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) { this.fontFormatting = cfRuleRecord.FontFormatting; this.workbook = workbook; }
/// <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)); }
/// <summary> /// Initializes a new instance of the <see cref="HSSFPatternFormatting"/> class. /// </summary> /// <param name="cfRuleRecord">The cf rule record.</param> public HSSFPatternFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) { this.cfRuleRecord = cfRuleRecord; this.patternFormatting = cfRuleRecord.PatternFormatting; }