Ejemplo n.º 1
0
 protected CFHeaderBase(CellRangeAddress[] regions, int nRules)
 {
     CellRangeAddress[] unmergedRanges  = regions;
     CellRangeAddress[] mergeCellRanges = CellRangeUtil.MergeCellRanges(unmergedRanges);
     CellRanges    = (mergeCellRanges);
     field_1_numcf = nRules;
 }
Ejemplo n.º 2
0
 public CFHeaderRecord(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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
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);
        }