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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-22 / +20 lines)
Lines 1527-1547 Link Here
1527
     * @param index of the region to unmerge
1527
     * @param index of the region to unmerge
1528
     */
1528
     */
1529
    @Override
1529
    @Override
1530
    @SuppressWarnings("deprecation")
1530
    public void removeMergedRegion(int index) {
1531
    public void removeMergedRegion(int index) {
1531
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1532
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1532
1533
1533
        int size = ctMergeCells.sizeOfMergeCellArray();
1534
        CTMergeCell[] oldMergeCellsArray = ctMergeCells.getMergeCellArray();
1534
        CTMergeCell[] mergeCellsArray = new CTMergeCell[size - 1];
1535
        int newArrayLength = oldMergeCellsArray.length - 1;
1535
        for (int i = 0 ; i < size ; i++) {
1536
        if (newArrayLength > 0) {
1536
            if (i < index) {
1537
            CTMergeCell[] newMergeCellsArray = new CTMergeCell[newArrayLength];
1537
                mergeCellsArray[i] = ctMergeCells.getMergeCellArray(i);
1538
            System.arraycopy(oldMergeCellsArray, 0, newMergeCellsArray, 0, index);
1538
            }
1539
            System.arraycopy(oldMergeCellsArray, index + 1, newMergeCellsArray, index, newArrayLength - index);
1539
            else if (i > index) {
1540
            ctMergeCells.setMergeCellArray(newMergeCellsArray);
1540
                mergeCellsArray[i - 1] = ctMergeCells.getMergeCellArray(i);
1541
            }
1542
        }
1543
        if(mergeCellsArray.length > 0){
1544
            ctMergeCells.setMergeCellArray(mergeCellsArray);
1545
        } else{
1541
        } else{
1546
            worksheet.unsetMergeCells();
1542
            worksheet.unsetMergeCells();
1547
        }
1543
        }
Lines 1556-1574 Link Here
1556
     *
1552
     *
1557
     * @param indices A set of the regions to unmerge
1553
     * @param indices A set of the regions to unmerge
1558
     */
1554
     */
1555
    @SuppressWarnings("deprecation")
1559
    public void removeMergedRegions(Set<Integer> indices) {
1556
    public void removeMergedRegions(Set<Integer> indices) {
1560
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1557
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1561
1558
1562
        int size = ctMergeCells.sizeOfMergeCellArray();
1559
        CTMergeCell[] oldMergeCellsArray = ctMergeCells.getMergeCellArray();
1563
        CTMergeCell[] mergeCellsArray = new CTMergeCell[size - indices.size()];
1560
        int newArrayLength = oldMergeCellsArray.length - indices.size();
1564
        for (int i = 0, d = 0 ; i < size ; i++) {
1561
        if (newArrayLength > 0) {
1562
            CTMergeCell[] newMergeCellsArray = new CTMergeCell[newArrayLength];
1563
            for (int i = 0, d = 0 ; i < oldMergeCellsArray.length; i++) {
1565
            if(!indices.contains(i)) {
1564
                if (!indices.contains(i)) {
1566
                mergeCellsArray[d] = ctMergeCells.getMergeCellArray(i);
1565
                    newMergeCellsArray[d] = oldMergeCellsArray[i];
1567
                d++;
1566
                    d++;
1568
            }
1567
                }
1569
        }
1568
            }
1570
        if(mergeCellsArray.length > 0){
1569
            ctMergeCells.setMergeCellArray(newMergeCellsArray);
1571
            ctMergeCells.setMergeCellArray(mergeCellsArray);
1572
        } else{
1570
        } else{
1573
            worksheet.unsetMergeCells();
1571
            worksheet.unsetMergeCells();
1574
        }
1572
        }

Return to bug 55280