Hi,

I believe problem is that as you remove regions, indices of remaining
regions shift - after removin 6 regions, you only have 6 remaining and thus
attempt to access 7th fails...

    Michal

On Wed, 15 May 2019, 13:08 rdhanara, <[email protected]> wrote:

> Hi,
> trying to shift the merged region to the specific position on the right
> side. So removing existing regions and creating the new merged region with
> the new range address.
>
> *Code:*
>                    ArrayList<CellRangeAddress> regions = new
> ArrayList<CellRangeAddress>();
>                    int totalMergedRegions=sheet.getNumMergedRegions();
>                    for (int i = 0; i < sheet.getNumMergedRegions(); i++){
>
>                  CellRangeAddress region = sheet.getMergedRegion(i);
>                  regions.add(region);
>               }
>                    for (int i = 0; i < totalMergedRegions; i++){
>                            sheet.removeMergedRegion(i);
>                       }
>
>                    for (CellRangeAddress region : regions){
>                             CellRangeAddress newRegion = new
> CellRangeAddress(
>                                region.getFirstRow(),
>                                region.getLastRow() ,
>                                region.getFirstColumn() + 9,
>                                region.getLastColumn() + 9);
>                             sheet.addMergedRegion(newRegion);
>                          }
>
> *Problem:*
>
> Totally I have 12 merged regions available. trying to shift them 9
> positions
> to the right.
> totalMergedRegions ==> 12
> but ,  sheet.removeMergedRegion(i);
>  giving index out of bound exception when i=6
> *i.e.    sheet.removeMergedRegion(6);*
>
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array
> index out of range: 5
>         at
>
> org.apache.poi.xssf.usermodel.XSSFSheet.removeMergedRegion(XSSFSheet.java:1433)
>
> *********************************
>
> Rest all the shifting happening fine. Kindly let me know the reason why
> getting out of bound  at 6 when there are totally 12 positions available ?
>
> Thanks In Advance ..!
>
>
>
>
>
> --
> Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to