示例#1
0
 public CFHeaderRecord(CellRangeAddress[] regions, int nRules)
 {
     CellRangeAddress[] unmergedRanges  = regions;
     CellRangeAddress[] mergeCellRanges = CellRangeUtil.MergeCellRanges(unmergedRanges);
     CellRanges    = mergeCellRanges;
     field_1_numcf = nRules;
 }
示例#2
0
 protected CFHeaderBase(CellRangeAddress[] regions, int nRules)
 {
     CellRangeAddress[] unmergedRanges  = regions;
     CellRangeAddress[] mergeCellRanges = CellRangeUtil.MergeCellRanges(unmergedRanges);
     CellRanges    = (mergeCellRanges);
     field_1_numcf = nRules;
 }
        public int AddConditionalFormatting(CellRangeAddress[] regions, IConditionalFormattingRule[] cfRules)
        {
            if (regions == null)
            {
                throw new ArgumentException("regions must not be null");
            }
            foreach (CellRangeAddress range in regions)
            {
                range.Validate(SpreadsheetVersion.EXCEL2007);
            }

            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");
            }
            XSSFConditionalFormattingRule[] hfRules;
            if (cfRules is XSSFConditionalFormattingRule[])
            {
                hfRules = (XSSFConditionalFormattingRule[])cfRules;
            }
            else
            {
                hfRules = new XSSFConditionalFormattingRule[cfRules.Length];
                Array.Copy(cfRules, 0, hfRules, 0, hfRules.Length);
            }

            CellRangeAddress[]       mergeCellRanges = CellRangeUtil.MergeCellRanges(regions);
            CT_ConditionalFormatting cf   = _sheet.GetCTWorksheet().AddNewConditionalFormatting();
            List <String>            refs = new List <String>();

            foreach (CellRangeAddress a in mergeCellRanges)
            {
                refs.Add(a.FormatAsString());
            }
            cf.sqref = (refs);


            int priority = 1;

            foreach (CT_ConditionalFormatting c in _sheet.GetCTWorksheet().conditionalFormatting)
            {
                priority += c.sizeOfCfRuleArray();
            }

            foreach (IConditionalFormattingRule rule in cfRules)
            {
                XSSFConditionalFormattingRule xRule = (XSSFConditionalFormattingRule)rule;
                xRule.GetCTCfRule().priority        = (priority++);
                cf.AddNewCfRule().Set(xRule.GetCTCfRule());
            }
            return(_sheet.GetCTWorksheet().SizeOfConditionalFormattingArray() - 1);
        }
示例#4
0
        public void TestMergeCellRanges()
        {
            CellRangeAddress cr1 = CellRangeAddress.ValueOf("A1:B1");
            CellRangeAddress cr2 = CellRangeAddress.ValueOf("A2:B2");

            CellRangeAddress[] cr3 = CellRangeUtil.MergeCellRanges(new CellRangeAddress[] { cr1, cr2 });
            Assert.AreEqual(1, cr3.Length);
            Assert.AreEqual("A1:B2", cr3[0].FormatAsString());
        }
示例#5
0
        //    public void testResolveRangeOverlap() {
        //        resolveRangeOverlapTest("C1:D2", "C2:C3");
        //    }

        private void CellRangeTest(string[] input, params string[] expectedOutput)
        {
            CellRangeAddress[] inputArr = new CellRangeAddress[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                inputArr[i] = CellRangeAddress.ValueOf(input[i]);
            }
            CellRangeAddress[] result = CellRangeUtil.MergeCellRanges(inputArr);
            VerifyExpectedResult(result, expectedOutput);
        }
示例#6
0
 public void TestContainsMethod()
 {
     CellRangeAddress[] ranges = sampleRanges;
     for (int i = 0; i != ranges.Length; i++)
     {
         for (int j = 0; j != ranges.Length; j++)
         {
             bool expectedResult = containsExpectedResults[i, j];
             Assert.AreEqual(expectedResult, CellRangeUtil.Contains(ranges[i], ranges[j]), "(" + i + "," + j + "): ");
         }
     }
 }
示例#7
0
        public int AddConditionalFormatting(CellRangeAddress[] regions, IConditionalFormattingRule[] cfRules)
        {
            if (regions == null)
            {
                throw new ArgumentException("regions must not be null");
            }
            foreach (CellRangeAddress range in regions)
            {
                range.Validate(SpreadsheetVersion.EXCEL2007);
            }

            if (cfRules == null)
            {
                throw new ArgumentException("cfRules must not be null");
            }
            if (cfRules.Length == 0)
            {
                throw new ArgumentException("cfRules must not be empty");
            }

            CellRangeAddress[]       mergeCellRanges = CellRangeUtil.MergeCellRanges(regions);
            CT_ConditionalFormatting cf = _sheet.GetCTWorksheet().AddNewConditionalFormatting();
            string refs = string.Empty;

            foreach (CellRangeAddress a in mergeCellRanges)
            {
                if (refs.Length == 0)
                {
                    refs = a.FormatAsString();
                }
                else
                {
                    refs += " " + a.FormatAsString();
                }
            }
            cf.sqref = refs;

            int priority = 1;

            foreach (CT_ConditionalFormatting c in _sheet.GetCTWorksheet().conditionalFormatting)
            {
                priority += c.sizeOfCfRuleArray();
            }

            foreach (IConditionalFormattingRule rule in cfRules)
            {
                XSSFConditionalFormattingRule xRule = (XSSFConditionalFormattingRule)rule;
                xRule.GetCTCfRule().priority        = (priority++);
                cf.AddNewCfRule().Set(xRule.GetCTCfRule());
            }
            return(_sheet.GetCTWorksheet().SizeOfConditionalFormattingArray() - 1);
        }
        public int AddConditionalFormatting(CellRangeAddress[] regions, IConditionalFormattingRule[] cfRules)
        {
            if (regions == null)
            {
                throw new ArgumentException("regions must not be null");
            }
            foreach (CellRangeAddressBase region in regions)
            {
                region.Validate(SpreadsheetVersion.EXCEL2007);
            }
            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");
            }
            if (!(cfRules is XSSFConditionalFormattingRule[]))
            {
                XSSFConditionalFormattingRule[] conditionalFormattingRuleArray = new XSSFConditionalFormattingRule[cfRules.Length];
                Array.Copy((Array)cfRules, 0, (Array)conditionalFormattingRuleArray, 0, conditionalFormattingRuleArray.Length);
            }
            CellRangeAddress[]       cellRangeAddressArray  = CellRangeUtil.MergeCellRanges(regions);
            CT_ConditionalFormatting conditionalFormatting1 = this._sheet.GetCTWorksheet().AddNewConditionalFormatting();
            List <string>            stringList             = new List <string>();

            foreach (CellRangeAddress cellRangeAddress in cellRangeAddressArray)
            {
                stringList.Add(cellRangeAddress.FormatAsString());
            }
            conditionalFormatting1.sqref = stringList;
            int num = 1;

            foreach (CT_ConditionalFormatting conditionalFormatting2 in this._sheet.GetCTWorksheet().conditionalFormatting)
            {
                num += conditionalFormatting2.sizeOfCfRuleArray();
            }
            foreach (XSSFConditionalFormattingRule cfRule in cfRules)
            {
                cfRule.GetCTCfRule().priority = num++;
                conditionalFormatting1.AddNewCfRule().Set(cfRule.GetCTCfRule());
            }
            return(this._sheet.GetCTWorksheet().SizeOfConditionalFormattingArray() - 1);
        }
示例#9
0
 public void TestIntersectMethod()
 {
     Assert.AreEqual(CellRangeUtil.OVERLAP, CellRangeUtil.Intersect(box0, box5));
     Assert.AreEqual(CellRangeUtil.OVERLAP, CellRangeUtil.Intersect(box5, box0));
     Assert.AreEqual(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.Intersect(box1, box4));
     Assert.AreEqual(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.Intersect(box4, box1));
     Assert.AreEqual(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.Intersect(box2, box3));
     Assert.AreEqual(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.Intersect(box3, box2));
     Assert.AreEqual(CellRangeUtil.INSIDE, CellRangeUtil.Intersect(box0, box1));
     Assert.AreEqual(CellRangeUtil.INSIDE, CellRangeUtil.Intersect(box0, box0));
     Assert.AreEqual(CellRangeUtil.ENCLOSES, CellRangeUtil.Intersect(box1, box0));
     Assert.AreEqual(CellRangeUtil.INSIDE, CellRangeUtil.Intersect(tenthColumn, oneCell));
     Assert.AreEqual(CellRangeUtil.ENCLOSES, CellRangeUtil.Intersect(oneCell, tenthColumn));
     Assert.AreEqual(CellRangeUtil.OVERLAP, CellRangeUtil.Intersect(tenthColumn, tenthRow));
     Assert.AreEqual(CellRangeUtil.OVERLAP, CellRangeUtil.Intersect(tenthRow, tenthColumn));
     Assert.AreEqual(CellRangeUtil.INSIDE, CellRangeUtil.Intersect(tenthColumn, tenthColumn));
     Assert.AreEqual(CellRangeUtil.INSIDE, CellRangeUtil.Intersect(tenthRow, tenthRow));
 }
示例#10
0
        public void TestHasSharedBorderMethod()
        {
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col1, col1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col2, col2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(col1, col2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(col2, col1));

            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row1, row1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row2, row2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(row1, row2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(row2, row1));

            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row1, col1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row1, col2));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col1, row1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col2, row1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row2, col1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(row2, col2));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col1, row2));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(col2, row2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(col2, col1));

            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box1, box1));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box1, box2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box1, box3));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box1, box4));

            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box2, box1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box2, box2));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box2, box3));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box2, box4));

            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box3, box1));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box3, box2));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box3, box3));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box3, box4));

            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box4, box1));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box4, box2));
            Assert.IsTrue(CellRangeUtil.HasExactSharedBorder(box4, box3));
            Assert.IsFalse(CellRangeUtil.HasExactSharedBorder(box4, box4));
        }