コード例 #1
0
        public void ShouldNotBeAbleToCreateArrayFormulaOnPreexistingMergedRegion()
        {
            /*
             *  m  = merged region
             *  f  = array formula
             *  fm = cell belongs to a merged region and an array formula (illegal, that's what this tests for)
             *
             *   A  B  C
             * 1    f  f
             * 2    fm fm
             * 3    f  f
             */
            IWorkbook workbook = _testDataProvider.CreateWorkbook();
            ISheet    sheet    = workbook.CreateSheet();

            CellRangeAddress mergedRegion = CellRangeAddress.ValueOf("B2:C2");

            sheet.AddMergedRegion(mergedRegion);
            CellRangeAddress arrayFormula = CellRangeAddress.ValueOf("C1:C3");

            Assume.That(mergedRegion.Intersects(arrayFormula));
            Assume.That(arrayFormula.Intersects(mergedRegion));
            try
            {
                sheet.SetArrayFormula("SUM(A1:A3)", arrayFormula);
                Assert.Fail("expected exception: should not be able to create an array formula that intersects with a merged region");
            }
            catch (InvalidOperationException e)
            {
                // expected
            }

            workbook.Close();
        }
コード例 #2
0
ファイル: RowShifter.cs プロジェクト: IMULMUL/npoi
        // Keep in sync with {@link ColumnShifter#removalNeeded}
        private bool removalNeeded(CellRangeAddress merged, int startRow, int endRow, int n, int lastCol)
        {
            int movedRows = endRow - startRow + 1;

            // build a range of the rows that are overwritten, i.e. the target-area, but without
            // rows that are moved along
            CellRangeAddress overwrite;

            if (n > 0)
            {
                // area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
                int firstRow = Math.Max(endRow + 1, endRow + n - movedRows);
                int lastRow  = endRow + n;
                overwrite = new CellRangeAddress(firstRow, lastRow, 0, lastCol);
            }
            else
            {
                // area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
                int firstRow = startRow + n;
                int lastRow  = Math.Min(startRow - 1, startRow + n + movedRows);
                overwrite = new CellRangeAddress(firstRow, lastRow, 0, lastCol);
            }

            // if the merged-region and the overwritten area intersect, we need to remove it
            return(merged.Intersects(overwrite));
        }
コード例 #3
0
ファイル: TestCellRangeAddress.cs プロジェクト: zzy092/npoi
 private static void assertNotIntersects(CellRangeAddress regionA, CellRangeAddress regionB)
 {
     if ((regionA.Intersects(regionB) || regionB.Intersects(regionA)))
     {
         String A = regionA.FormatAsString();
         String B = regionB.FormatAsString();
         Assert.Fail("expected: regions " + A + " and " + B + " do not intersect");
     }
 }