コード例 #1
0
        public void TestAddMergedRegion()
        {
            InternalSheet sheet        = InternalSheet.CreateSheet();
            int           regionsToAdd = 4096;
            int           startRecords = sheet.Records.Count;

            //simple Test that Adds a load of regions
            for (int n = 0; n < regionsToAdd; n++)
            {
                int index = sheet.AddMergedRegion(0, 0, 1, 1);
                Assert.AreEqual(index, n, "Merged region index expected to be " + n + " got " + index);
            }

            //test all the regions were indeed Added
            Assert.AreEqual(sheet.NumMergedRegions, regionsToAdd);

            //test that the regions were spread out over the appropriate number of records
            MergedCellListener mcListener = new MergedCellListener();

            sheet.VisitContainedRecords(mcListener, 0);
            int recordsAdded    = mcListener.Count;
            int recordsExpected = regionsToAdd / 1027;

            if ((regionsToAdd % 1027) != 0)
            {
                recordsExpected++;
            }
            Assert.AreEqual(recordsAdded, recordsExpected, "The " + regionsToAdd + " merged regions should have been spRead out over " + recordsExpected + " records, not " + recordsAdded);
            // Check we can't Add one with invalid date
            try
            {
                sheet.AddMergedRegion(10, 10, 9, 12);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' row (9) must not be less than the 'from' row (10)", e.Message);
            }
            try
            {
                sheet.AddMergedRegion(10, 10, 12, 9);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' col (9) must not be less than the 'from' col (10)", e.Message);
            }
        }
コード例 #2
0
ファイル: TestSheet.cs プロジェクト: 89sos98/npoi
        public void TestAddMergedRegion()
        {
            InternalSheet sheet = InternalSheet.CreateSheet();
            int regionsToAdd = 4096;
            int startRecords = sheet.Records.Count;

            //simple Test that Adds a load of regions
            for (int n = 0; n < regionsToAdd; n++)
            {
                int index = sheet.AddMergedRegion(0, 0, 1, 1);
                Assert.AreEqual(index, n, "Merged region index expected to be " + n + " got " + index);
            }

            //test all the regions were indeed Added
            Assert.AreEqual(sheet.NumMergedRegions, regionsToAdd);

            //test that the regions were spread out over the appropriate number of records
            MergedCellListener mcListener = new MergedCellListener();
            sheet.VisitContainedRecords(mcListener, 0);
            int recordsAdded = mcListener.Count; 
            int recordsExpected = regionsToAdd / 1027;
            if ((regionsToAdd % 1027) != 0)
                recordsExpected++;
            Assert.AreEqual(recordsAdded, recordsExpected, "The " + regionsToAdd + " merged regions should have been spRead out over " + recordsExpected + " records, not " + recordsAdded);
            // Check we can't Add one with invalid date
            try
            {
                sheet.AddMergedRegion(10, 10, 9, 12);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' row (9) must not be less than the 'from' row (10)", e.Message);
            }
            try
            {
                sheet.AddMergedRegion(10, 10, 12, 9);
                Assert.Fail("Expected an exception to occur");
            }
            catch (ArgumentException e)
            {
                // occurs during successful Test
                Assert.AreEqual("The 'to' col (9) must not be less than the 'from' col (10)", e.Message);
            }
        }