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); }
/// <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)); }
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> /// Gets Conditional Formatting object at a particular index /// @param index /// of the Conditional Formatting object to fetch /// </summary> /// <param name="index">Conditional Formatting object</param> /// <returns></returns> public IConditionalFormatting GetConditionalFormattingAt(int index) { CFRecordsAggregate cf = _conditionalFormattingTable.Get(index); if (cf == null) { return(null); } return(new HSSFConditionalFormatting(_sheet, cf)); }
/// <summary> /// Initializes a new instance of the <see cref="HSSFConditionalFormatting"/> class. /// </summary> /// <param name="workbook">The workbook.</param> /// <param name="cfAggregate">The cf aggregate.</param> public HSSFConditionalFormatting(HSSFWorkbook workbook, CFRecordsAggregate cfAggregate) { if (workbook == null) { throw new ArgumentException("workbook must not be null"); } if (cfAggregate == null) { throw new ArgumentException("cfAggregate must not be null"); } _workbook = workbook; this.cfAggregate = cfAggregate; }
/// <summary> /// Initializes a new instance of the <see cref="HSSFConditionalFormatting"/> class. /// </summary> /// <param name="workbook">The workbook.</param> /// <param name="cfAggregate">The cf aggregate.</param> public HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) { if (sheet == null) { throw new ArgumentException("workbook must not be null"); } if (cfAggregate == null) { throw new ArgumentException("cfAggregate must not be null"); } this.sheet = sheet; this.cfAggregate = cfAggregate; }
/// <summary> /// Adds a copy of HSSFConditionalFormatting object to the sheet /// This method could be used to copy HSSFConditionalFormatting object /// from one sheet to another. /// </summary> /// <param name="cf">HSSFConditionalFormatting object</param> /// <returns>index of the new Conditional Formatting object</returns> /// <example> /// HSSFConditionalFormatting cf = sheet.GetConditionalFormattingAt(index); /// newSheet.AddConditionalFormatting(cf); /// </example> public int AddConditionalFormatting(HSSFConditionalFormatting cf) { CFRecordsAggregate cfraClone = cf.CFRecordsAggregate.CloneCFAggregate(); return(_conditionalFormattingTable.Add(cfraClone)); }
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); }
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)); } } }
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); }