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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (-6 / +8 lines)
Lines 439-454 Link Here
439
     *
439
     *
440
     * @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
440
     * @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
441
     */
441
     */
442
    @SuppressWarnings("deprecation")
442
    protected void onDocumentWrite(){
443
    protected void onDocumentWrite(){
443
        // check if cells in the CTRow are ordered
444
        // check if cells in the CTRow are ordered
444
        boolean isOrdered = true;
445
        boolean isOrdered = true;
445
        if(_row.sizeOfCArray() != _cells.size()) {
446
        CTCell[] cArray = _row.getCArray();
447
        if (cArray.length != _cells.size()) {
446
            isOrdered = false;
448
            isOrdered = false;
447
        } else {
449
        } else {
448
            int i = 0;
450
            int i = 0;
449
            for (XSSFCell cell : _cells.values()) {
451
            for (XSSFCell cell : _cells.values()) {
450
                CTCell c1 = cell.getCTCell();
452
                CTCell c1 = cell.getCTCell();
451
                CTCell c2 = _row.getCArray(i++); 
453
                CTCell c2 = cArray[i++];
452
454
453
                String r1 = c1.getR();
455
                String r1 = c1.getR();
454
                String r2 = c2.getR();
456
                String r2 = c2.getR();
Lines 460-476 Link Here
460
        }
462
        }
461
463
462
        if(!isOrdered){
464
        if(!isOrdered){
463
            CTCell[] cArray = new CTCell[_cells.size()];
465
            cArray = new CTCell[_cells.size()];
464
            int i = 0;
466
            int i = 0;
465
            for (Map.Entry<Integer, XSSFCell> entry : _cells.entrySet()) {
467
            for (XSSFCell xssfCell : _cells.values()) {
466
                cArray[i] = (CTCell) entry.getValue().getCTCell().copy();
468
                cArray[i] = (CTCell) xssfCell.getCTCell().copy();
467
                
469
                
468
                // we have to copy and re-create the XSSFCell here because the 
470
                // we have to copy and re-create the XSSFCell here because the 
469
                // elements as otherwise setCArray below invalidates all the columns!
471
                // elements as otherwise setCArray below invalidates all the columns!
470
                // see Bug 56170, XMLBeans seems to always release previous objects
472
                // see Bug 56170, XMLBeans seems to always release previous objects
471
                // in the CArray, so we need to provide completely new ones here!
473
                // in the CArray, so we need to provide completely new ones here!
472
                //_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
474
                //_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
473
                entry.getValue().setCTCell(cArray[i]);
475
                xssfCell.setCTCell(cArray[i]);
474
                i++;
476
                i++;
475
            }
477
            }
476
478
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (-2 / +4 lines)
Lines 1370-1375 Link Here
1370
     * @param pos the position that we want to insert the sheet into (0 based)
1370
     * @param pos the position that we want to insert the sheet into (0 based)
1371
     */
1371
     */
1372
    @Override
1372
    @Override
1373
    @SuppressWarnings("deprecation")
1373
    public void setSheetOrder(String sheetname, int pos) {
1374
    public void setSheetOrder(String sheetname, int pos) {
1374
        int idx = getSheetIndex(sheetname);
1375
        int idx = getSheetIndex(sheetname);
1375
        sheets.add(pos, sheets.remove(idx));
1376
        sheets.add(pos, sheets.remove(idx));
Lines 1381-1388 Link Here
1381
        newcts.set(cts);
1382
        newcts.set(cts);
1382
1383
1383
        //notify sheets
1384
        //notify sheets
1384
        for(int i=0; i < sheets.size(); i++) {
1385
        CTSheet[] sheetArray = ct.getSheetArray();
1385
            sheets.get(i).sheet = ct.getSheetArray(i);
1386
        for(int i=0; i < sheetArray.length; i++) {
1387
            sheets.get(i).sheet = sheetArray[i];
1386
        }
1388
        }
1387
    }
1389
    }
1388
1390
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-272 / +201 lines)
Lines 602-607 Link Here
602
        return null;
602
        return null;
603
    }
603
    }
604
604
605
    @SuppressWarnings("deprecation")
606
    private int[] getBreaks(CTPageBreak ctPageBreak) {
607
        CTBreak[] brkArray = ctPageBreak.getBrkArray();
608
        int[] breaks = new int[brkArray.length];
609
        for (int i = 0 ; i < brkArray.length ; i++) {
610
            breaks[i] = (int) brkArray[i].getId() - 1;
611
        }
612
        return breaks;
613
    }
614
615
    @SuppressWarnings("deprecation")
616
    private void removeBreak(int index, CTPageBreak ctPageBreak) {
617
        int index1 = index + 1;
618
        CTBreak[] brkArray = ctPageBreak.getBrkArray();
619
        for (int i = 0 ; i < brkArray.length ; i++) {
620
            if (brkArray[i].getId() == index1) {
621
                ctPageBreak.removeBrk(i);
622
                // TODO: check if we can break here, i.e. if a page can have more than 1 break on the same id
623
            }
624
        }
625
    }
626
605
    /**
627
    /**
606
     * Vertical page break information used for print layout view, page layout view, drawing print breaks
628
     * Vertical page break information used for print layout view, page layout view, drawing print breaks
607
     * in normal view, and for printing the worksheet.
629
     * in normal view, and for printing the worksheet.
Lines 609-630 Link Here
609
     * @return column indexes of all the vertical page breaks, never <code>null</code>
631
     * @return column indexes of all the vertical page breaks, never <code>null</code>
610
     */
632
     */
611
    @Override
633
    @Override
612
    @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
613
    public int[] getColumnBreaks() {
634
    public int[] getColumnBreaks() {
614
        if (!worksheet.isSetColBreaks() || worksheet.getColBreaks().sizeOfBrkArray() == 0) {
635
        return worksheet.isSetColBreaks() ? getBreaks(worksheet.getColBreaks()) : new int[0];
615
            return new int[0];
616
        }
636
    }
617
637
618
        CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
619
620
        int[] breaks = new int[brkArray.length];
621
        for (int i = 0 ; i < brkArray.length ; i++) {
622
            CTBreak brk = brkArray[i];
623
            breaks[i] = (int)brk.getId() - 1;
624
        }
625
        return breaks;
626
    }
627
628
    /**
638
    /**
629
     * Get the actual column width (in units of 1/256th of a character width )
639
     * Get the actual column width (in units of 1/256th of a character width )
630
     *
640
     *
Lines 705-712 Link Here
705
     * @param value true for right to left, false otherwise.
715
     * @param value true for right to left, false otherwise.
706
     */
716
     */
707
    @Override
717
    @Override
708
    public void setRightToLeft(boolean value)
718
    public void setRightToLeft(boolean value) {
709
    {
710
       CTSheetView view = getDefaultSheetView();
719
       CTSheetView view = getDefaultSheetView();
711
       view.setRightToLeft(value);
720
       view.setRightToLeft(value);
712
    }
721
    }
Lines 717-726 Link Here
717
     * @return whether the text is displayed in right-to-left mode in the window
726
     * @return whether the text is displayed in right-to-left mode in the window
718
     */
727
     */
719
    @Override
728
    @Override
720
    public boolean isRightToLeft()
729
    public boolean isRightToLeft() {
721
    {
722
       CTSheetView view = getDefaultSheetView();
730
       CTSheetView view = getDefaultSheetView();
723
       return view == null ? false : view.getRightToLeft();
731
       return view != null && view.getRightToLeft();
724
    }
732
    }
725
733
726
    /**
734
    /**
Lines 757-763 Link Here
757
    @Override
765
    @Override
758
    public boolean isDisplayZeros(){
766
    public boolean isDisplayZeros(){
759
        CTSheetView view = getDefaultSheetView();
767
        CTSheetView view = getDefaultSheetView();
760
        return view == null ? true : view.getShowZeros();
768
        return view == null || view.getShowZeros();
761
    }
769
    }
762
770
763
    /**
771
    /**
Lines 779-785 Link Here
779
     */
787
     */
780
    @Override
788
    @Override
781
    public int getFirstRowNum() {
789
    public int getFirstRowNum() {
782
        return _rows.size() == 0 ? 0 : _rows.firstKey();
790
        return _rows.isEmpty() ? 0 : _rows.firstKey();
783
    }
791
    }
784
792
785
    /**
793
    /**
Lines 897-903 Link Here
897
905
898
    @Override
906
    @Override
899
    public int getLastRowNum() {
907
    public int getLastRowNum() {
900
        return _rows.size() == 0 ? 0 : _rows.lastKey();
908
        return _rows.isEmpty() ? 0 : _rows.lastKey();
901
    }
909
    }
902
910
903
    @Override
911
    @Override
Lines 1032-1040 Link Here
1032
    }
1040
    }
1033
1041
1034
    /**
1042
    /**
1035
     * Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
1043
     * Returns the number of physically defined rows (NOT the number of rows in the sheet)
1036
     *
1044
     *
1037
     * @return the number of phsyically defined rows
1045
     * @return the number of physically defined rows
1038
     */
1046
     */
1039
    @Override
1047
    @Override
1040
    public int getPhysicalNumberOfRows() {
1048
    public int getPhysicalNumberOfRows() {
Lines 1122-1141 Link Here
1122
     * @return row indexes of all the horizontal page breaks, never <code>null</code>
1130
     * @return row indexes of all the horizontal page breaks, never <code>null</code>
1123
     */
1131
     */
1124
    @Override
1132
    @Override
1125
    @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
1126
    public int[] getRowBreaks() {
1133
    public int[] getRowBreaks() {
1127
        if (!worksheet.isSetRowBreaks() || worksheet.getRowBreaks().sizeOfBrkArray() == 0) {
1134
        return worksheet.isSetRowBreaks() ? getBreaks(worksheet.getRowBreaks()) : new int[0];
1128
            return new int[0];
1129
        }
1130
1135
1131
        CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray();
1136
    }
1132
        int[] breaks = new int[brkArray.length];
1133
        for (int i = 0 ; i < brkArray.length ; i++) {
1134
            CTBreak brk = brkArray[i];
1135
            breaks[i] = (int)brk.getId() - 1;
1136
        }
1137
        return breaks;
1138
    }
1139
1137
1140
    /**
1138
    /**
1141
     * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
1139
     * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
Lines 1334-1355 Link Here
1334
    }
1332
    }
1335
1333
1336
    private short getMaxOutlineLevelRows(){
1334
    private short getMaxOutlineLevelRows(){
1337
        short outlineLevel=0;
1335
        int outlineLevel = 0;
1338
        for(XSSFRow xrow : _rows.values()){
1336
        for (XSSFRow xrow : _rows.values()) {
1339
            outlineLevel=xrow.getCTRow().getOutlineLevel()>outlineLevel? xrow.getCTRow().getOutlineLevel(): outlineLevel;
1337
            outlineLevel = Math.max(outlineLevel, xrow.getCTRow().getOutlineLevel());
1340
        }
1338
        }
1341
        return outlineLevel;
1339
        return (short) outlineLevel;
1342
    }
1340
    }
1343
1341
1344
1342
1345
    @SuppressWarnings("deprecation")
1343
    @SuppressWarnings("deprecation")
1346
    private short getMaxOutlineLevelCols() {
1344
    private short getMaxOutlineLevelCols() {
1347
        CTCols ctCols = worksheet.getColsArray(0);
1345
        CTCols ctCols = worksheet.getColsArray(0);
1348
        short outlineLevel = 0;
1346
        int outlineLevel = 0;
1349
        for (CTCol col : ctCols.getColArray()) {
1347
        for (CTCol col : ctCols.getColArray()) {
1350
            outlineLevel = col.getOutlineLevel() > outlineLevel ? col.getOutlineLevel() : outlineLevel;
1348
            outlineLevel = Math.max(outlineLevel, col.getOutlineLevel());
1351
        }
1349
        }
1352
        return outlineLevel;
1350
        return (short) outlineLevel;
1353
    }
1351
    }
1354
1352
1355
    /**
1353
    /**
Lines 1357-1364 Link Here
1357
     */
1355
     */
1358
    @Override
1356
    @Override
1359
    public boolean isColumnBroken(int column) {
1357
    public boolean isColumnBroken(int column) {
1360
        int[] colBreaks = getColumnBreaks();
1358
        for (int colBreak : getColumnBreaks()) {
1361
        for (int colBreak : colBreaks) {
1362
            if (colBreak == column) {
1359
            if (colBreak == column) {
1363
                return true;
1360
                return true;
1364
            }
1361
            }
Lines 1477-1484 Link Here
1477
     */
1474
     */
1478
    @Override
1475
    @Override
1479
    public boolean isRowBroken(int row) {
1476
    public boolean isRowBroken(int row) {
1480
        int[] rowBreaks = getRowBreaks();
1477
        for (int rowBreak : getRowBreaks()) {
1481
        for (int rowBreak : rowBreaks) {
1482
            if (rowBreak == row) {
1478
            if (rowBreak == row) {
1483
                return true;
1479
                return true;
1484
            }
1480
            }
Lines 1486-1491 Link Here
1486
        return false;
1482
        return false;
1487
    }
1483
    }
1488
1484
1485
    private void setBreak(int id, CTPageBreak ctPgBreak, int lastIndex) {
1486
        CTBreak brk = ctPgBreak.addNewBrk();
1487
        brk.setId(id + 1); // this is id of the element which is 1-based: <row r="1" ... >
1488
        brk.setMan(true);
1489
        brk.setMax(lastIndex); //end column of the break
1490
1491
        int nPageBreaks = ctPgBreak.sizeOfBrkArray();
1492
        ctPgBreak.setCount(nPageBreaks);
1493
        ctPgBreak.setManualBreakCount(nPageBreaks);
1494
    }
1495
1489
    /**
1496
    /**
1490
     * Sets a page break at the indicated row
1497
     * Sets a page break at the indicated row
1491
     * Breaks occur above the specified row and left of the specified column inclusive.
1498
     * Breaks occur above the specified row and left of the specified column inclusive.
Lines 1499-1513 Link Here
1499
     */
1506
     */
1500
    @Override
1507
    @Override
1501
    public void setRowBreak(int row) {
1508
    public void setRowBreak(int row) {
1502
        CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
1509
        if (!isRowBroken(row)) {
1503
        if (! isRowBroken(row)) {
1504
            CTBreak brk = pgBreak.addNewBrk();
1510
            CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
1505
            brk.setId(row + 1); // this is id of the row element which is 1-based: <row r="1" ... >
1511
            setBreak(row, pgBreak, SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
1506
            brk.setMan(true);
1507
            brk.setMax(SpreadsheetVersion.EXCEL2007.getLastColumnIndex()); //end column of the break
1508
1509
            pgBreak.setCount(pgBreak.sizeOfBrkArray());
1510
            pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
1511
        }
1512
        }
1512
    }
1513
    }
1513
1514
Lines 1515-1557 Link Here
1515
     * Removes a page break at the indicated column
1516
     * Removes a page break at the indicated column
1516
     */
1517
     */
1517
    @Override
1518
    @Override
1518
    @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
1519
    public void removeColumnBreak(int column) {
1519
    public void removeColumnBreak(int column) {
1520
        if (!worksheet.isSetColBreaks()) {
1520
        if (worksheet.isSetColBreaks()) {
1521
            // no breaks
1521
            removeBreak(column, worksheet.getColBreaks());
1522
            return;
1522
        } // else no breaks
1523
        }
1523
    }
1524
1524
1525
        CTPageBreak pgBreak = worksheet.getColBreaks();
1526
        CTBreak[] brkArray = pgBreak.getBrkArray();
1527
        for (int i = 0 ; i < brkArray.length ; i++) {
1528
            if (brkArray[i].getId() == (column + 1)) {
1529
                pgBreak.removeBrk(i);
1530
            }
1531
        }
1532
    }
1533
1534
    /**
1525
    /**
1535
     * Removes a merged region of cells (hence letting them free)
1526
     * Removes a merged region of cells (hence letting them free)
1536
     *
1527
     *
1537
     * @param index of the region to unmerge
1528
     * @param index of the region to unmerge
1538
     */
1529
     */
1539
    @Override
1530
    @Override
1531
    @SuppressWarnings("deprecation")
1540
    public void removeMergedRegion(int index) {
1532
    public void removeMergedRegion(int index) {
1541
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1533
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1542
1534
1543
        int size = ctMergeCells.sizeOfMergeCellArray();
1535
        CTMergeCell[] oldMergeCellsArray = ctMergeCells.getMergeCellArray();
1544
        CTMergeCell[] mergeCellsArray = new CTMergeCell[size - 1];
1536
        int newArrayLength = oldMergeCellsArray.length - 1;
1545
        for (int i = 0 ; i < size ; i++) {
1537
        if (newArrayLength > 0) {
1546
            if (i < index) {
1538
            CTMergeCell[] newMergeCellsArray = new CTMergeCell[newArrayLength];
1547
                mergeCellsArray[i] = ctMergeCells.getMergeCellArray(i);
1539
            System.arraycopy(oldMergeCellsArray, 0, newMergeCellsArray, 0, index);
1548
            }
1540
            System.arraycopy(oldMergeCellsArray, index + 1, newMergeCellsArray, index, newArrayLength - index);
1549
            else if (i > index) {
1541
            ctMergeCells.setMergeCellArray(newMergeCellsArray);
1550
                mergeCellsArray[i - 1] = ctMergeCells.getMergeCellArray(i);
1551
            }
1552
        }
1553
        if(mergeCellsArray.length > 0){
1554
            ctMergeCells.setMergeCellArray(mergeCellsArray);
1555
        } else{
1542
        } else{
1556
            worksheet.unsetMergeCells();
1543
            worksheet.unsetMergeCells();
1557
        }
1544
        }
Lines 1559-1584 Link Here
1559
1546
1560
    /**
1547
    /**
1561
     * Removes a number of merged regions of cells (hence letting them free)
1548
     * Removes a number of merged regions of cells (hence letting them free)
1562
     * 
1549
     *
1563
     * This method can be used to bulk-remove merged regions in a way
1550
     * This method can be used to bulk-remove merged regions in a way
1564
     * much faster than calling removeMergedRegion() for every single 
1551
     * much faster than calling removeMergedRegion() for every single
1565
     * merged region.
1552
     * merged region.
1566
     *
1553
     *
1567
     * @param indices A set of the regions to unmerge
1554
     * @param indices A set of the regions to unmerge
1568
     */
1555
     */
1556
    @SuppressWarnings("deprecation")
1569
    public void removeMergedRegions(Set<Integer> indices) {
1557
    public void removeMergedRegions(Set<Integer> indices) {
1570
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1558
        CTMergeCells ctMergeCells = worksheet.getMergeCells();
1571
1559
1572
        int size = ctMergeCells.sizeOfMergeCellArray();
1560
        CTMergeCell[] oldMergeCellsArray = ctMergeCells.getMergeCellArray();
1573
        CTMergeCell[] mergeCellsArray = new CTMergeCell[size - indices.size()];
1561
        int newArrayLength = oldMergeCellsArray.length - indices.size();
1574
        for (int i = 0, d = 0 ; i < size ; i++) {
1562
        if (newArrayLength > 0) {
1563
            CTMergeCell[] newMergeCellsArray = new CTMergeCell[newArrayLength];
1564
            for (int i = 0, d = 0 ; i < oldMergeCellsArray.length; i++) {
1575
            if(!indices.contains(i)) {
1565
                if (!indices.contains(i)) {
1576
                mergeCellsArray[d] = ctMergeCells.getMergeCellArray(i);
1566
                    newMergeCellsArray[d] = oldMergeCellsArray[i];
1577
                d++;
1567
                    d++;
1578
            }
1568
                }
1579
        }
1569
            }
1580
        if(mergeCellsArray.length > 0){
1570
            ctMergeCells.setMergeCellArray(newMergeCellsArray);
1581
            ctMergeCells.setMergeCellArray(mergeCellsArray);
1582
        } else{
1571
        } else{
1583
            worksheet.unsetMergeCells();
1572
            worksheet.unsetMergeCells();
1584
        }
1573
        }
Lines 1609-1627 Link Here
1609
     * Removes the page break at the indicated row
1598
     * Removes the page break at the indicated row
1610
     */
1599
     */
1611
    @Override
1600
    @Override
1612
    @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
1613
    public void removeRowBreak(int row) {
1601
    public void removeRowBreak(int row) {
1614
        if(!worksheet.isSetRowBreaks()) {
1602
        if (worksheet.isSetRowBreaks()) {
1615
            return;
1603
            removeBreak(row, worksheet.getRowBreaks());
1604
        } // else no breaks
1616
        }
1605
    }
1617
        CTPageBreak pgBreak = worksheet.getRowBreaks();
1618
        CTBreak[] brkArray = pgBreak.getBrkArray();
1619
        for (int i = 0 ; i < brkArray.length ; i++) {
1620
            if (brkArray[i].getId() == (row + 1)) {
1621
                pgBreak.removeBrk(i);
1622
            }
1623
        }
1624
    }
1625
1606
1626
    /**
1607
    /**
1627
     * Control if Excel should be asked to recalculate all formulas on this sheet
1608
     * Control if Excel should be asked to recalculate all formulas on this sheet
Lines 1734-1748 Link Here
1734
     */
1715
     */
1735
    @Override
1716
    @Override
1736
    public void setColumnBreak(int column) {
1717
    public void setColumnBreak(int column) {
1737
        if (! isColumnBroken(column)) {
1718
        if (!isColumnBroken(column)) {
1738
            CTPageBreak pgBreak = worksheet.isSetColBreaks() ? worksheet.getColBreaks() : worksheet.addNewColBreaks();
1719
            CTPageBreak pgBreak = worksheet.isSetColBreaks() ? worksheet.getColBreaks() : worksheet.addNewColBreaks();
1739
            CTBreak brk = pgBreak.addNewBrk();
1720
            setBreak(column, pgBreak, SpreadsheetVersion.EXCEL2007.getLastRowIndex());
1740
            brk.setId(column + 1);  // this is id of the row element which is 1-based: <row r="1" ... >
1741
            brk.setMan(true);
1742
            brk.setMax(SpreadsheetVersion.EXCEL2007.getLastRowIndex()); //end row of the break
1743
1744
            pgBreak.setCount(pgBreak.sizeOfBrkArray());
1745
            pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
1746
        }
1721
        }
1747
    }
1722
    }
1748
1723
Lines 1772-1794 Link Here
1772
                .getOutlineLevel(), true);
1747
                .getOutlineLevel(), true);
1773
1748
1774
        // write collapse field
1749
        // write collapse field
1775
        setColumn(lastColMax + 1, null, 0, null, null, Boolean.TRUE);
1750
        setColumn(lastColMax + 1, 0, null, null, Boolean.TRUE);
1776
1751
1777
    }
1752
    }
1778
1753
1779
    private void setColumn(int targetColumnIx, Short xfIndex, Integer style,
1754
    @SuppressWarnings("deprecation")
1755
    private void setColumn(int targetColumnIx, Integer style,
1780
            Integer level, Boolean hidden, Boolean collapsed) {
1756
                           Integer level, Boolean hidden, Boolean collapsed) {
1781
        CTCols cols = worksheet.getColsArray(0);
1757
        CTCols cols = worksheet.getColsArray(0);
1782
        CTCol ci = null;
1758
        CTCol ci = null;
1783
        int k = 0;
1759
        for (CTCol tci : cols.getColArray()) {
1784
        for (k = 0; k < cols.sizeOfColArray(); k++) {
1760
            long tciMin = tci.getMin();
1785
            CTCol tci = cols.getColArray(k);
1761
            long tciMax = tci.getMax();
1786
            if (tci.getMin() >= targetColumnIx
1762
            if (tciMin >= targetColumnIx && tciMax <= targetColumnIx) {
1787
                    && tci.getMax() <= targetColumnIx) {
1788
                ci = tci;
1763
                ci = tci;
1789
                break;
1764
                break;
1790
            }
1765
            }
1791
            if (tci.getMin() > targetColumnIx) {
1766
            if (tciMin > targetColumnIx) {
1792
                // call column infos after k are for later columns
1767
                // call column infos after k are for later columns
1793
                break; // exit now so k will be the correct insert pos
1768
                break; // exit now so k will be the correct insert pos
1794
            }
1769
            }
Lines 1805-1840 Link Here
1805
            return;
1780
            return;
1806
        }
1781
        }
1807
1782
1808
        boolean styleChanged = style != null
1783
        boolean styleChanged = style != null && ci.getStyle() != style;
1809
        && ci.getStyle() != style;
1784
        boolean levelChanged = level != null && ci.getOutlineLevel() != level;
1810
        boolean levelChanged = level != null
1785
        boolean hiddenChanged = hidden != null && ci.getHidden() != hidden;
1811
        && ci.getOutlineLevel() != level;
1786
        boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed;
1812
        boolean hiddenChanged = hidden != null
1787
        boolean columnChanged = levelChanged || hiddenChanged || collapsedChanged || styleChanged;
1813
        && ci.getHidden() != hidden;
1814
        boolean collapsedChanged = collapsed != null
1815
        && ci.getCollapsed() != collapsed;
1816
        boolean columnChanged = levelChanged || hiddenChanged
1817
        || collapsedChanged || styleChanged;
1818
        if (!columnChanged) {
1788
        if (!columnChanged) {
1819
            // do nothing...nothing changed.
1789
            // do nothing...nothing changed.
1820
            return;
1790
            return;
1821
        }
1791
        }
1822
1792
1823
        if (ci.getMin() == targetColumnIx && ci.getMax() == targetColumnIx) {
1793
        long ciMin = ci.getMin();
1794
        long ciMax = ci.getMax();
1795
        if (ciMin == targetColumnIx && ciMax == targetColumnIx) {
1824
            // ColumnInfo ci for a single column, the target column
1796
            // ColumnInfo ci for a single column, the target column
1825
            unsetCollapsed(collapsed, ci);
1797
            unsetCollapsed(collapsed, ci);
1826
            return;
1798
            return;
1827
        }
1799
        }
1828
1800
1829
        if (ci.getMin() == targetColumnIx || ci.getMax() == targetColumnIx) {
1801
        if (ciMin == targetColumnIx || ciMax == targetColumnIx) {
1830
            // The target column is at either end of the multi-column ColumnInfo
1802
            // The target column is at either end of the multi-column ColumnInfo
1831
            // ci
1803
            // ci
1832
            // we'll just divide the info and create a new one
1804
            // we'll just divide the info and create a new one
1833
            if (ci.getMin() == targetColumnIx) {
1805
            if (ciMin == targetColumnIx) {
1834
                ci.setMin(targetColumnIx + 1);
1806
                ci.setMin(targetColumnIx + 1);
1835
            } else {
1807
            } else {
1836
                ci.setMax(targetColumnIx - 1);
1808
                ci.setMax(targetColumnIx - 1);
1837
                k++; // adjust insert pos to insert after
1838
            }
1809
            }
1839
            CTCol nci = columnHelper.cloneCol(cols, ci);
1810
            CTCol nci = columnHelper.cloneCol(cols, ci);
1840
            nci.setMin(targetColumnIx);
1811
            nci.setMin(targetColumnIx);
Lines 1843-1854 Link Here
1843
1814
1844
        } else {
1815
        } else {
1845
            // split to 3 records
1816
            // split to 3 records
1846
            CTCol ciStart = ci;
1847
            CTCol ciMid = columnHelper.cloneCol(cols, ci);
1817
            CTCol ciMid = columnHelper.cloneCol(cols, ci);
1848
            CTCol ciEnd = columnHelper.cloneCol(cols, ci);
1818
            CTCol ciEnd = columnHelper.cloneCol(cols, ci);
1849
            int lastcolumn = (int) ci.getMax();
1819
            int lastcolumn = (int) ciMax;
1850
1820
1851
            ciStart.setMax(targetColumnIx - 1);
1821
            ci.setMax(targetColumnIx - 1);
1852
1822
1853
            ciMid.setMin(targetColumnIx);
1823
            ciMid.setMin(targetColumnIx);
1854
            ciMid.setMax(targetColumnIx);
1824
            ciMid.setMax(targetColumnIx);
Lines 1877-1890 Link Here
1877
     *                the col info index of the start of the outline group
1847
     *                the col info index of the start of the outline group
1878
     * @return the column index of the last column in the outline group
1848
     * @return the column index of the last column in the outline group
1879
     */
1849
     */
1850
    @SuppressWarnings("deprecation")
1880
    private int setGroupHidden(int pIdx, int level, boolean hidden) {
1851
    private int setGroupHidden(int pIdx, int level, boolean hidden) {
1881
        CTCols cols = worksheet.getColsArray(0);
1852
        CTCols cols = worksheet.getColsArray(0);
1882
        int idx = pIdx;
1853
        int idx = pIdx;
1883
        CTCol columnInfo = cols.getColArray(idx);
1854
        CTCol[] colArray = cols.getColArray();
1884
        while (idx < cols.sizeOfColArray()) {
1855
        CTCol columnInfo = colArray[idx];
1856
        while (idx < colArray.length) {
1885
            columnInfo.setHidden(hidden);
1857
            columnInfo.setHidden(hidden);
1886
            if (idx + 1 < cols.sizeOfColArray()) {
1858
            if (idx + 1 < colArray.length) {
1887
                CTCol nextColumnInfo = cols.getColArray(idx + 1);
1859
                CTCol nextColumnInfo = colArray[idx + 1];
1888
1860
1889
                if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
1861
                if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
1890
                    break;
1862
                    break;
Lines 1901-1917 Link Here
1901
    }
1873
    }
1902
1874
1903
    private boolean isAdjacentBefore(CTCol col, CTCol other_col) {
1875
    private boolean isAdjacentBefore(CTCol col, CTCol other_col) {
1904
        return (col.getMax() == (other_col.getMin() - 1));
1876
        return col.getMax() == other_col.getMin() - 1;
1905
    }
1877
    }
1906
1878
1879
    @SuppressWarnings("deprecation")
1907
    private int findStartOfColumnOutlineGroup(int pIdx) {
1880
    private int findStartOfColumnOutlineGroup(int pIdx) {
1908
        // Find the start of the group.
1881
        // Find the start of the group.
1909
        CTCols cols = worksheet.getColsArray(0);
1882
        CTCols cols = worksheet.getColsArray(0);
1910
        CTCol columnInfo = cols.getColArray(pIdx);
1883
        CTCol[] colArray = cols.getColArray();
1884
        CTCol columnInfo = colArray[pIdx];
1911
        int level = columnInfo.getOutlineLevel();
1885
        int level = columnInfo.getOutlineLevel();
1912
        int idx = pIdx;
1886
        int idx = pIdx;
1913
        while (idx != 0) {
1887
        while (idx != 0) {
1914
            CTCol prevColumnInfo = cols.getColArray(idx - 1);
1888
            CTCol prevColumnInfo = colArray[idx - 1];
1915
            if (!isAdjacentBefore(prevColumnInfo, columnInfo)) {
1889
            if (!isAdjacentBefore(prevColumnInfo, columnInfo)) {
1916
                break;
1890
                break;
1917
            }
1891
            }
Lines 1924-1937 Link Here
1924
        return idx;
1898
        return idx;
1925
    }
1899
    }
1926
1900
1901
    @SuppressWarnings("deprecation")
1927
    private int findEndOfColumnOutlineGroup(int colInfoIndex) {
1902
    private int findEndOfColumnOutlineGroup(int colInfoIndex) {
1928
        CTCols cols = worksheet.getColsArray(0);
1903
        CTCols cols = worksheet.getColsArray(0);
1929
        // Find the end of the group.
1904
        // Find the end of the group.
1930
        CTCol columnInfo = cols.getColArray(colInfoIndex);
1905
        CTCol[] colArray = cols.getColArray();
1906
        CTCol columnInfo = colArray[colInfoIndex];
1931
        int level = columnInfo.getOutlineLevel();
1907
        int level = columnInfo.getOutlineLevel();
1932
        int idx = colInfoIndex;
1908
        int idx = colInfoIndex;
1933
        while (idx < cols.sizeOfColArray() - 1) {
1909
        int lastIdx = colArray.length - 1;
1934
            CTCol nextColumnInfo = cols.getColArray(idx + 1);
1910
        while (idx < lastIdx) {
1911
            CTCol nextColumnInfo = colArray[idx + 1];
1935
            if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
1912
            if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
1936
                break;
1913
                break;
1937
            }
1914
            }
Lines 1944-1949 Link Here
1944
        return idx;
1921
        return idx;
1945
    }
1922
    }
1946
1923
1924
    @SuppressWarnings("deprecation")
1947
    private void expandColumn(int columnIndex) {
1925
    private void expandColumn(int columnIndex) {
1948
        CTCols cols = worksheet.getColsArray(0);
1926
        CTCols cols = worksheet.getColsArray(0);
1949
        CTCol col = columnHelper.getColumn(columnIndex, false);
1927
        CTCol col = columnHelper.getColumn(columnIndex, false);
Lines 1974-1985 Link Here
1974
        // is the enclosing group
1952
        // is the enclosing group
1975
        // hidden bit only is altered for this outline level. ie. don't
1953
        // hidden bit only is altered for this outline level. ie. don't
1976
        // uncollapse contained groups
1954
        // uncollapse contained groups
1977
        CTCol columnInfo = cols.getColArray(endIdx);
1955
        CTCol[] colArray = cols.getColArray();
1956
        CTCol columnInfo = colArray[endIdx];
1978
        if (!isColumnGroupHiddenByParent(idx)) {
1957
        if (!isColumnGroupHiddenByParent(idx)) {
1979
            int outlineLevel = columnInfo.getOutlineLevel();
1958
            short outlineLevel = columnInfo.getOutlineLevel();
1980
            boolean nestedGroup = false;
1959
            boolean nestedGroup = false;
1981
            for (int i = startIdx; i <= endIdx; i++) {
1960
            for (int i = startIdx; i <= endIdx; i++) {
1982
                CTCol ci = cols.getColArray(i);
1961
                CTCol ci = colArray[i];
1983
                if (outlineLevel == ci.getOutlineLevel()) {
1962
                if (outlineLevel == ci.getOutlineLevel()) {
1984
                    ci.unsetHidden();
1963
                    ci.unsetHidden();
1985
                    if (nestedGroup) {
1964
                    if (nestedGroup) {
Lines 1993-2012 Link Here
1993
        }
1972
        }
1994
        // Write collapse flag (stored in a single col info record after this
1973
        // Write collapse flag (stored in a single col info record after this
1995
        // outline group)
1974
        // outline group)
1996
        setColumn((int) columnInfo.getMax() + 1, null, null, null,
1975
        setColumn((int) columnInfo.getMax() + 1, null, null,
1997
                Boolean.FALSE, Boolean.FALSE);
1976
                Boolean.FALSE, Boolean.FALSE);
1998
    }
1977
    }
1999
1978
1979
    @SuppressWarnings("deprecation")
2000
    private boolean isColumnGroupHiddenByParent(int idx) {
1980
    private boolean isColumnGroupHiddenByParent(int idx) {
2001
        CTCols cols = worksheet.getColsArray(0);
1981
        CTCols cols = worksheet.getColsArray(0);
2002
        // Look out outline details of end
1982
        // Look out outline details of end
2003
        int endLevel = 0;
1983
        int endLevel = 0;
2004
        boolean endHidden = false;
1984
        boolean endHidden = false;
2005
        int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
1985
        int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
2006
        if (endOfOutlineGroupIdx < cols.sizeOfColArray()) {
1986
        CTCol[] colArray = cols.getColArray();
2007
            CTCol nextInfo = cols.getColArray(endOfOutlineGroupIdx + 1);
1987
        if (endOfOutlineGroupIdx < colArray.length) {
2008
            if (isAdjacentBefore(cols.getColArray(endOfOutlineGroupIdx),
1988
            CTCol nextInfo = colArray[endOfOutlineGroupIdx + 1];
2009
                    nextInfo)) {
1989
            if (isAdjacentBefore(colArray[endOfOutlineGroupIdx], nextInfo)) {
2010
                endLevel = nextInfo.getOutlineLevel();
1990
                endLevel = nextInfo.getOutlineLevel();
2011
                endHidden = nextInfo.getHidden();
1991
                endHidden = nextInfo.getHidden();
2012
            }
1992
            }
Lines 2016-2025 Link Here
2016
        boolean startHidden = false;
1996
        boolean startHidden = false;
2017
        int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup(idx);
1997
        int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup(idx);
2018
        if (startOfOutlineGroupIdx > 0) {
1998
        if (startOfOutlineGroupIdx > 0) {
2019
            CTCol prevInfo = cols.getColArray(startOfOutlineGroupIdx - 1);
1999
            CTCol prevInfo = colArray[startOfOutlineGroupIdx - 1];
2020
2000
2021
            if (isAdjacentBefore(prevInfo, cols
2001
            if (isAdjacentBefore(prevInfo, colArray[startOfOutlineGroupIdx])) {
2022
                    .getColArray(startOfOutlineGroupIdx))) {
2023
                startLevel = prevInfo.getOutlineLevel();
2002
                startLevel = prevInfo.getOutlineLevel();
2024
                startHidden = prevInfo.getHidden();
2003
                startHidden = prevInfo.getHidden();
2025
            }
2004
            }
Lines 2031-2036 Link Here
2031
        return startHidden;
2010
        return startHidden;
2032
    }
2011
    }
2033
2012
2013
    @SuppressWarnings("deprecation")
2034
    private int findColInfoIdx(int columnValue, int fromColInfoIdx) {
2014
    private int findColInfoIdx(int columnValue, int fromColInfoIdx) {
2035
        CTCols cols = worksheet.getColsArray(0);
2015
        CTCols cols = worksheet.getColsArray(0);
2036
2016
Lines 2043-2050 Link Here
2043
                    "fromIdx parameter out of range: " + fromColInfoIdx);
2023
                    "fromIdx parameter out of range: " + fromColInfoIdx);
2044
        }
2024
        }
2045
2025
2046
        for (int k = fromColInfoIdx; k < cols.sizeOfColArray(); k++) {
2026
        CTCol[] colArray = cols.getColArray();
2047
            CTCol ci = cols.getColArray(k);
2027
        for (int k = fromColInfoIdx; k < colArray.length; k++) {
2028
            CTCol ci = colArray[k];
2048
2029
2049
            if (containsColumn(ci, columnValue)) {
2030
            if (containsColumn(ci, columnValue)) {
2050
                return k;
2031
                return k;
Lines 2069-2084 Link Here
2069
     * @param idx
2050
     * @param idx
2070
     * @return a boolean represented if the column is collapsed
2051
     * @return a boolean represented if the column is collapsed
2071
     */
2052
     */
2053
    @SuppressWarnings("deprecation")
2072
    private boolean isColumnGroupCollapsed(int idx) {
2054
    private boolean isColumnGroupCollapsed(int idx) {
2073
        CTCols cols = worksheet.getColsArray(0);
2055
        CTCols cols = worksheet.getColsArray(0);
2056
        CTCol[] colArray = cols.getColArray();
2074
        int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
2057
        int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
2075
        int nextColInfoIx = endOfOutlineGroupIdx + 1;
2058
        int nextColInfoIx = endOfOutlineGroupIdx + 1;
2076
        if (nextColInfoIx >= cols.sizeOfColArray()) {
2059
        if (nextColInfoIx >= colArray.length) {
2077
            return false;
2060
            return false;
2078
        }
2061
        }
2079
        CTCol nextColInfo = cols.getColArray(nextColInfoIx);
2062
        CTCol nextColInfo = colArray[nextColInfoIx];
2080
2063
2081
        CTCol col = cols.getColArray(endOfOutlineGroupIdx);
2064
        CTCol col = colArray[endOfOutlineGroupIdx];
2082
        if (!isAdjacentBefore(col, nextColInfo)) {
2065
        if (!isAdjacentBefore(col, nextColInfo)) {
2083
            return false;
2066
            return false;
2084
        }
2067
        }
Lines 2285-2291 Link Here
2285
     */
2268
     */
2286
    private int findStartOfRowOutlineGroup(int rowIndex) {
2269
    private int findStartOfRowOutlineGroup(int rowIndex) {
2287
        // Find the start of the group.
2270
        // Find the start of the group.
2288
        int level = getRow(rowIndex).getCTRow().getOutlineLevel();
2271
        short level = getRow(rowIndex).getCTRow().getOutlineLevel();
2289
        int currentRow = rowIndex;
2272
        int currentRow = rowIndex;
2290
        while (getRow(currentRow) != null) {
2273
        while (getRow(currentRow) != null) {
2291
            if (getRow(currentRow).getCTRow().getOutlineLevel() < level)
2274
            if (getRow(currentRow).getCTRow().getOutlineLevel() < level)
Lines 2296-2302 Link Here
2296
    }
2279
    }
2297
2280
2298
    private int writeHidden(XSSFRow xRow, int rowIndex, boolean hidden) {
2281
    private int writeHidden(XSSFRow xRow, int rowIndex, boolean hidden) {
2299
        int level = xRow.getCTRow().getOutlineLevel();
2282
        short level = xRow.getCTRow().getOutlineLevel();
2300
        for (Iterator<Row> it = rowIterator(); it.hasNext();) {
2283
        for (Iterator<Row> it = rowIterator(); it.hasNext();) {
2301
            xRow = (XSSFRow) it.next();
2284
            xRow = (XSSFRow) it.next();
2302
2285
Lines 2343-2352 Link Here
2343
        // is the enclosing group
2326
        // is the enclosing group
2344
        // hidden bit only is altered for this outline level. ie. don't
2327
        // hidden bit only is altered for this outline level. ie. don't
2345
        // un-collapse contained groups
2328
        // un-collapse contained groups
2329
        short level = row.getCTRow().getOutlineLevel();
2346
        if (!isRowGroupHiddenByParent(rowNumber)) {
2330
        if (!isRowGroupHiddenByParent(rowNumber)) {
2347
            for (int i = startIdx; i < endIdx; i++) {
2331
            for (int i = startIdx; i < endIdx; i++) {
2348
                if (row.getCTRow().getOutlineLevel() == getRow(i).getCTRow()
2332
                if (level == getRow(i).getCTRow().getOutlineLevel()) {
2349
                        .getOutlineLevel()) {
2350
                    getRow(i).getCTRow().unsetHidden();
2333
                    getRow(i).getCTRow().unsetHidden();
2351
                } else if (!isRowGroupCollapsed(i)) {
2334
                } else if (!isRowGroupCollapsed(i)) {
2352
                    getRow(i).getCTRow().unsetHidden();
2335
                    getRow(i).getCTRow().unsetHidden();
Lines 2365-2371 Link Here
2365
     * @param row the zero based row index to find from
2348
     * @param row the zero based row index to find from
2366
     */
2349
     */
2367
    public int findEndOfRowOutlineGroup(int row) {
2350
    public int findEndOfRowOutlineGroup(int row) {
2368
        int level = getRow(row).getCTRow().getOutlineLevel();
2351
        short level = getRow(row).getCTRow().getOutlineLevel();
2369
        int currentRow;
2352
        int currentRow;
2370
        for (currentRow = row; currentRow < getLastRowNum(); currentRow++) {
2353
        for (currentRow = row; currentRow < getLastRowNum(); currentRow++) {
2371
            if (getRow(currentRow) == null
2354
            if (getRow(currentRow) == null
Lines 2621-2631 Link Here
2621
        for (int i = fromRow; i <= toRow; i++) {
2604
        for (int i = fromRow; i <= toRow; i++) {
2622
            XSSFRow xrow = getRow(i);
2605
            XSSFRow xrow = getRow(i);
2623
            if (xrow != null) {
2606
            if (xrow != null) {
2624
                CTRow ctrow = xrow.getCTRow();
2607
                CTRow ctRow = xrow.getCTRow();
2625
                short outlinelevel = ctrow.getOutlineLevel();
2608
                int outlineLevel = ctRow.getOutlineLevel();
2626
                ctrow.setOutlineLevel((short) (outlinelevel - 1));
2609
                ctRow.setOutlineLevel((short) (outlineLevel - 1));
2627
                //remove a row only if the row has no cell and if the outline level is 0
2610
                //remove a row only if the row has no cell and if the outline level is 0
2628
                if (ctrow.getOutlineLevel() == 0 && xrow.getFirstCellNum() == -1) {
2611
                if (outlineLevel == 1 && xrow.getFirstCellNum() == -1) {
2629
                    removeRow(xrow);
2612
                    removeRow(xrow);
2630
                }
2613
                }
2631
            }
2614
            }
Lines 2737-2749 Link Here
2737
     *  so we can decide about writing it to disk or not
2720
     *  so we can decide about writing it to disk or not
2738
     */
2721
     */
2739
    public boolean hasComments() {
2722
    public boolean hasComments() {
2740
        if(sheetComments == null) { return false; }
2723
        return sheetComments != null && sheetComments.getNumberOfComments() > 0;
2741
        return (sheetComments.getNumberOfComments() > 0);
2742
    }
2724
    }
2743
2725
2744
    protected int getNumberOfComments() {
2726
    protected int getNumberOfComments() {
2745
        if(sheetComments == null) { return 0; }
2727
        return sheetComments == null ? 0 : sheetComments.getNumberOfComments();
2746
        return sheetComments.getNumberOfComments();
2747
    }
2728
    }
2748
2729
2749
    private CTSelection getSheetTypeSelection() {
2730
    private CTSelection getSheetTypeSelection() {
Lines 2842-2848 Link Here
2842
            CTCellFormula sf = (CTCellFormula)f.copy();
2823
            CTCellFormula sf = (CTCellFormula)f.copy();
2843
            CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
2824
            CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
2844
            CellReference cellRef = new CellReference(cell);
2825
            CellReference cellRef = new CellReference(cell);
2845
            // If the shared formula range preceeds the master cell then the preceding  part is discarded, e.g.
2826
            // If the shared formula range precedes the master cell then the preceding  part is discarded, e.g.
2846
            // if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85
2827
            // if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85
2847
            // see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
2828
            // see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
2848
            if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){
2829
            if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){
Lines 2920-3080 Link Here
2920
     * @return true when Autofilters are locked and the sheet is protected.
2901
     * @return true when Autofilters are locked and the sheet is protected.
2921
     */
2902
     */
2922
    public boolean isAutoFilterLocked() {
2903
    public boolean isAutoFilterLocked() {
2923
        if (isSheetLocked()) {
2904
        return isSheetLocked() && safeGetProtectionField().getAutoFilter();
2924
            return safeGetProtectionField().getAutoFilter();
2925
        }
2905
    }
2926
        return false;
2927
    }
2928
2906
2929
    /**
2907
    /**
2930
     * @return true when Deleting columns is locked and the sheet is protected.
2908
     * @return true when Deleting columns is locked and the sheet is protected.
2931
     */
2909
     */
2932
    public boolean isDeleteColumnsLocked() {
2910
    public boolean isDeleteColumnsLocked() {
2933
        if (isSheetLocked()) {
2911
        return isSheetLocked() && safeGetProtectionField().getDeleteColumns();
2934
            return safeGetProtectionField().getDeleteColumns();
2935
        }
2912
    }
2936
        return false;
2937
    }
2938
2913
2939
    /**
2914
    /**
2940
     * @return true when Deleting rows is locked and the sheet is protected.
2915
     * @return true when Deleting rows is locked and the sheet is protected.
2941
     */
2916
     */
2942
    public boolean isDeleteRowsLocked() {
2917
    public boolean isDeleteRowsLocked() {
2943
        if (isSheetLocked()) {
2918
        return isSheetLocked() && safeGetProtectionField().getDeleteRows();
2944
            return safeGetProtectionField().getDeleteRows();
2945
        }
2919
    }
2946
        return false;
2947
    }
2948
2920
2949
    /**
2921
    /**
2950
     * @return true when Formatting cells is locked and the sheet is protected.
2922
     * @return true when Formatting cells is locked and the sheet is protected.
2951
     */
2923
     */
2952
    public boolean isFormatCellsLocked() {
2924
    public boolean isFormatCellsLocked() {
2953
        if (isSheetLocked()) {
2925
        return isSheetLocked() && safeGetProtectionField().getFormatCells();
2954
            return safeGetProtectionField().getFormatCells();
2955
        }
2926
    }
2956
        return false;
2957
    }
2958
2927
2959
    /**
2928
    /**
2960
     * @return true when Formatting columns is locked and the sheet is protected.
2929
     * @return true when Formatting columns is locked and the sheet is protected.
2961
     */
2930
     */
2962
    public boolean isFormatColumnsLocked() {
2931
    public boolean isFormatColumnsLocked() {
2963
        if (isSheetLocked()) {
2932
        return isSheetLocked() && safeGetProtectionField().getFormatColumns();
2964
            return safeGetProtectionField().getFormatColumns();
2965
        }
2933
    }
2966
        return false;
2967
    }
2968
2934
2969
    /**
2935
    /**
2970
     * @return true when Formatting rows is locked and the sheet is protected.
2936
     * @return true when Formatting rows is locked and the sheet is protected.
2971
     */
2937
     */
2972
    public boolean isFormatRowsLocked() {
2938
    public boolean isFormatRowsLocked() {
2973
        if (isSheetLocked()) {
2939
        return isSheetLocked() && safeGetProtectionField().getFormatRows();
2974
            return safeGetProtectionField().getFormatRows();
2975
        }
2940
    }
2976
        return false;
2977
    }
2978
2941
2979
    /**
2942
    /**
2980
     * @return true when Inserting columns is locked and the sheet is protected.
2943
     * @return true when Inserting columns is locked and the sheet is protected.
2981
     */
2944
     */
2982
    public boolean isInsertColumnsLocked() {
2945
    public boolean isInsertColumnsLocked() {
2983
        if (isSheetLocked()) {
2946
        return isSheetLocked() && safeGetProtectionField().getInsertColumns();
2984
            return safeGetProtectionField().getInsertColumns();
2985
        }
2947
    }
2986
        return false;
2987
    }
2988
2948
2989
    /**
2949
    /**
2990
     * @return true when Inserting hyperlinks is locked and the sheet is protected.
2950
     * @return true when Inserting hyperlinks is locked and the sheet is protected.
2991
     */
2951
     */
2992
    public boolean isInsertHyperlinksLocked() {
2952
    public boolean isInsertHyperlinksLocked() {
2993
        if (isSheetLocked()) {
2953
        return isSheetLocked() && safeGetProtectionField().getInsertHyperlinks();
2994
            return safeGetProtectionField().getInsertHyperlinks();
2995
        }
2954
    }
2996
        return false;
2997
    }
2998
2955
2999
    /**
2956
    /**
3000
     * @return true when Inserting rows is locked and the sheet is protected.
2957
     * @return true when Inserting rows is locked and the sheet is protected.
3001
     */
2958
     */
3002
    public boolean isInsertRowsLocked() {
2959
    public boolean isInsertRowsLocked() {
3003
        if (isSheetLocked()) {
2960
        return isSheetLocked() && safeGetProtectionField().getInsertRows();
3004
            return safeGetProtectionField().getInsertRows();
3005
        }
2961
    }
3006
        return false;
3007
    }
3008
2962
3009
    /**
2963
    /**
3010
     * @return true when Pivot tables are locked and the sheet is protected.
2964
     * @return true when Pivot tables are locked and the sheet is protected.
3011
     */
2965
     */
3012
    public boolean isPivotTablesLocked() {
2966
    public boolean isPivotTablesLocked() {
3013
        if (isSheetLocked()) {
2967
        return isSheetLocked() && safeGetProtectionField().getPivotTables();
3014
            return safeGetProtectionField().getPivotTables();
3015
        }
2968
    }
3016
        return false;
3017
    }
3018
2969
3019
    /**
2970
    /**
3020
     * @return true when Sorting is locked and the sheet is protected.
2971
     * @return true when Sorting is locked and the sheet is protected.
3021
     */
2972
     */
3022
    public boolean isSortLocked() {
2973
    public boolean isSortLocked() {
3023
        if (isSheetLocked()) {
2974
        return isSheetLocked() && safeGetProtectionField().getSort();
3024
            return safeGetProtectionField().getSort();
3025
        }
2975
    }
3026
        return false;
3027
    }
3028
2976
3029
    /**
2977
    /**
3030
     * @return true when Objects are locked and the sheet is protected.
2978
     * @return true when Objects are locked and the sheet is protected.
3031
     */
2979
     */
3032
    public boolean isObjectsLocked() {
2980
    public boolean isObjectsLocked() {
3033
        if (isSheetLocked()) {
2981
        return isSheetLocked() && safeGetProtectionField().getObjects();
3034
            return safeGetProtectionField().getObjects();
3035
        }
2982
    }
3036
        return false;
3037
    }
3038
2983
3039
    /**
2984
    /**
3040
     * @return true when Scenarios are locked and the sheet is protected.
2985
     * @return true when Scenarios are locked and the sheet is protected.
3041
     */
2986
     */
3042
    public boolean isScenariosLocked() {
2987
    public boolean isScenariosLocked() {
3043
        if (isSheetLocked()) {
2988
        return isSheetLocked() && safeGetProtectionField().getScenarios();
3044
            return safeGetProtectionField().getScenarios();
3045
        }
2989
    }
3046
        return false;
3047
    }
3048
2990
3049
    /**
2991
    /**
3050
     * @return true when Selection of locked cells is locked and the sheet is protected.
2992
     * @return true when Selection of locked cells is locked and the sheet is protected.
3051
     */
2993
     */
3052
    public boolean isSelectLockedCellsLocked() {
2994
    public boolean isSelectLockedCellsLocked() {
3053
        if (isSheetLocked()) {
2995
        return isSheetLocked() && safeGetProtectionField().getSelectLockedCells();
3054
            return safeGetProtectionField().getSelectLockedCells();
3055
        }
2996
    }
3056
        return false;
3057
    }
3058
2997
3059
    /**
2998
    /**
3060
     * @return true when Selection of unlocked cells is locked and the sheet is protected.
2999
     * @return true when Selection of unlocked cells is locked and the sheet is protected.
3061
     */
3000
     */
3062
    public boolean isSelectUnlockedCellsLocked() {
3001
    public boolean isSelectUnlockedCellsLocked() {
3063
        if (isSheetLocked()) {
3002
        return isSheetLocked() && safeGetProtectionField().getSelectUnlockedCells();
3064
            return safeGetProtectionField().getSelectUnlockedCells();
3065
        }
3003
    }
3066
        return false;
3067
    }
3068
3004
3069
    /**
3005
    /**
3070
     * @return true when Sheet is Protected.
3006
     * @return true when Sheet is Protected.
3071
     */
3007
     */
3072
    public boolean isSheetLocked() {
3008
    public boolean isSheetLocked() {
3073
        if (worksheet.isSetSheetProtection()) {
3009
        return worksheet.isSetSheetProtection() && safeGetProtectionField().getSheet();
3074
            return safeGetProtectionField().getSheet();
3075
        }
3010
    }
3076
        return false;
3077
    }
3078
3011
3079
    /**
3012
    /**
3080
     * Enable sheet protection
3013
     * Enable sheet protection
Lines 3530-3539 Link Here
3530
     * Returns any tables associated with this Sheet
3463
     * Returns any tables associated with this Sheet
3531
     */
3464
     */
3532
    public List<XSSFTable> getTables() {
3465
    public List<XSSFTable> getTables() {
3533
       List<XSSFTable> tableList = new ArrayList<XSSFTable>(
3466
        return new ArrayList<XSSFTable>(tables.values());
3534
             tables.values()
3535
       );
3536
       return tableList;
3537
    }
3467
    }
3538
3468
3539
    @Override
3469
    @Override
Lines 3656-3673 Link Here
3656
        String c = "";
3586
        String c = "";
3657
        String r = "";
3587
        String r = "";
3658
3588
3659
        if(startC == -1 && endC == -1) {
3589
        if (startC != -1 || endC != -1) {
3660
        } else {
3661
          c = escapedName + "!$" + colRef.getCellRefParts()[2]
3590
          c = escapedName + "!$" + colRef.getCellRefParts()[2]
3662
              + ":$" + colRef2.getCellRefParts()[2];
3591
              + ":$" + colRef2.getCellRefParts()[2];
3663
        }
3592
        }
3664
3593
3665
        if (startR == -1 && endR == -1) {
3594
        if (startR != -1 || endR != -1) {
3666
3595
            if (!rowRef.getCellRefParts()[1].equals("0")
3667
        } else if (!rowRef.getCellRefParts()[1].equals("0")
3668
            && !rowRef2.getCellRefParts()[1].equals("0")) {
3596
                && !rowRef2.getCellRefParts()[1].equals("0")) {
3669
           r = escapedName + "!$" + rowRef.getCellRefParts()[1]
3597
               r = escapedName + "!$" + rowRef.getCellRefParts()[1]
3670
                 + ":$" + rowRef2.getCellRefParts()[1];
3598
                     + ":$" + rowRef2.getCellRefParts()[1];
3599
            }
3671
        }
3600
        }
3672
3601
3673
        StringBuilder rng = new StringBuilder();
3602
        StringBuilder rng = new StringBuilder();
(-)src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java (-5 / +7 lines)
Lines 98-106 Link Here
98
        return comments.getAuthors().getAuthorArray((int)authorId);
98
        return comments.getAuthors().getAuthorArray((int)authorId);
99
    }
99
    }
100
100
101
    @SuppressWarnings("deprecation")
101
    public int findAuthor(String author) {
102
    public int findAuthor(String author) {
102
        for (int i = 0 ; i < comments.getAuthors().sizeOfAuthorArray() ; i++) {
103
        String[] authorArray = comments.getAuthors().getAuthorArray();
103
            if (comments.getAuthors().getAuthorArray(i).equals(author)) {
104
        for (int i = 0 ; i < authorArray.length; i++) {
105
            if (authorArray[i].equals(author)) {
104
                return i;
106
                return i;
105
            }
107
            }
106
        }
108
        }
Lines 150-158 Link Here
150
    public boolean removeComment(String cellRef) {
152
    public boolean removeComment(String cellRef) {
151
        CTCommentList lst = comments.getCommentList();
153
        CTCommentList lst = comments.getCommentList();
152
        if(lst != null) {
154
        if(lst != null) {
153
            int commentCount = lst.sizeOfCommentArray();
155
            CTComment[] commentArray = lst.getCommentArray();
154
            for(int i=0; i < commentCount; i++) {
156
            for (int i = 0; i < commentArray.length; i++) {
155
                CTComment comment = lst.getCommentArray(i);
157
                CTComment comment = commentArray[i];
156
                if (cellRef.equals(comment.getRef())) {
158
                if (cellRef.equals(comment.getRef())) {
157
                    lst.removeComment(i);
159
                    lst.removeComment(i);
158
160

Return to bug 56854