View | Details | Raw Unified | Return to bug 60397
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (+11 lines)
Lines 399-404 Link Here
399
        return _sh.addMergedRegionUnsafe(region);
399
        return _sh.addMergedRegionUnsafe(region);
400
    }
400
    }
401
401
402
    /**
403
     * Adds a merged region of cells (hence those cells form one)
404
     *
405
     * @param region (rowfrom/colfrom-rowto/colto) to merge
406
     */
407
    @Override
408
    public void insertMergedRegionUnsafe(CellRangeAddress region)
409
    {
410
        _sh.insertMergedRegionUnsafe(region);
411
    }
412
402
    /**
413
    /**
403
     * Verify that merged regions do not intersect multi-cell array formulas and
414
     * Verify that merged regions do not intersect multi-cell array formulas and
404
     * no merged regions intersect another merged region in this sheet.
415
     * no merged regions intersect another merged region in this sheet.
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-5 / +22 lines)
Lines 366-372 Link Here
366
     */
366
     */
367
    @Override
367
    @Override
368
    public int addMergedRegion(CellRangeAddress region) {
368
    public int addMergedRegion(CellRangeAddress region) {
369
        return addMergedRegion(region, true);
369
        return addMergedRegion(region, true).sizeOfMergeCellArray();
370
    }
370
    }
371
371
372
    /**
372
    /**
Lines 384-390 Link Here
384
     */
384
     */
385
    @Override
385
    @Override
386
    public int addMergedRegionUnsafe(CellRangeAddress region) {
386
    public int addMergedRegionUnsafe(CellRangeAddress region) {
387
        return addMergedRegion(region, false);
387
        return addMergedRegion(region, false).sizeOfMergeCellArray();
388
    }
389
390
    /**
391
     * Adds a merged region of cells (hence those cells form one).
392
     * Skips validation. It is possible to create overlapping merged regions
393
     * or create a merged region that intersects a multi-cell array formula
394
     * with this formula, which may result in a corrupt workbook.
395
     *
396
     * To check for merged regions overlapping array formulas or other merged regions
397
     * after addMergedRegionUnsafe has been called, call {@link #validateMergedRegions()}, which runs in O(n^2) time.
398
     *
399
     * @param region to merge
400
     * @throws IllegalArgumentException if region contains fewer than 2 cells
401
     */
402
    @Override
403
    public void insertMergedRegionUnsafe(CellRangeAddress region) {
404
        addMergedRegion(region, false);
388
    }
405
    }
389
406
390
    /**
407
    /**
Lines 394-405 Link Here
394
     *
411
     *
395
     * @param region to merge
412
     * @param region to merge
396
     * @param validate whether to validate merged region
413
     * @param validate whether to validate merged region
397
     * @return index of this region
414
     * @return merged cells
398
     * @throws IllegalArgumentException if region contains fewer than 2 cells (this check is inexpensive and is performed regardless of <tt>validate</tt>)
415
     * @throws IllegalArgumentException if region contains fewer than 2 cells (this check is inexpensive and is performed regardless of <tt>validate</tt>)
399
     * @throws IllegalStateException if region intersects with a multi-cell array formula
416
     * @throws IllegalStateException if region intersects with a multi-cell array formula
400
     * @throws IllegalStateException if region intersects with an existing region on this sheet
417
     * @throws IllegalStateException if region intersects with an existing region on this sheet
401
     */
418
     */
402
    private int addMergedRegion(CellRangeAddress region, boolean validate) {
419
    private CTMergeCells addMergedRegion(CellRangeAddress region, boolean validate) {
403
        if (region.getNumberOfCells() < 2) {
420
        if (region.getNumberOfCells() < 2) {
404
            throw new IllegalArgumentException("Merged region " + region.formatAsString() + " must contain 2 or more cells");
421
            throw new IllegalArgumentException("Merged region " + region.formatAsString() + " must contain 2 or more cells");
405
        }
422
        }
Lines 418-424 Link Here
418
        CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();
435
        CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();
419
        CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
436
        CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
420
        ctMergeCell.setRef(region.formatAsString());
437
        ctMergeCell.setRef(region.formatAsString());
421
        return ctMergeCells.sizeOfMergeCellArray();
438
        return ctMergeCells;
422
    }
439
    }
423
440
424
    /**
441
    /**
(-)src/java/org/apache/poi/ss/usermodel/Sheet.java (+16 lines)
Lines 297-302 Link Here
297
     */
297
     */
298
    int addMergedRegionUnsafe(CellRangeAddress region);
298
    int addMergedRegionUnsafe(CellRangeAddress region);
299
299
300
    /**
301
     * Adds a merged region of cells (hence those cells form one).
302
     * Skips validation. It is possible to create overlapping merged regions
303
     * or create a merged region that intersects a multi-cell array formula
304
     * with this formula, which may result in a corrupt workbook.
305
     *
306
     * To check for merged regions overlapping array formulas or other merged regions
307
     * after addMergedRegionUnsafe has been called, call {@link #validateMergedRegions()}, which runs in O(n^2) time.
308
     *
309
     * @param region to merge
310
     * @throws IllegalArgumentException if region contains fewer than 2 cells
311
     */
312
    default void insertMergedRegionUnsafe(CellRangeAddress region) {
313
        addMergedRegionUnsafe(region);
314
    }
315
300
    /**
316
    /**
301
     * Verify that merged regions do not intersect multi-cell array formulas and
317
     * Verify that merged regions do not intersect multi-cell array formulas and
302
     * no merged regions intersect another merged region in this sheet.
318
     * no merged regions intersect another merged region in this sheet.

Return to bug 60397