0

I want to modify an excel, I want to add a new row (using shiftrow() method) but it doesn't work. I know why I am having this error but is there any other way how to do it? When meeting a certain requirement I want to shift a row and fill those cells.

  .................
  ......................
 Iterator<Row> rowIterator = sheet.rowIterator();

    while(rowIterator.hasNext()) {
        XSSFRow currentRow = (XSSFRow) rowIterator.next();
        Iterator<Cell> cellIterator = currentRow.cellIterator();
        while(cellIterator.hasNext()) {
            XSSFCell currentCell = (XSSFCell) cellIterator.next();

            if(currentCell.getStringCellValue().equalsIgnoreCase("xxxxxx")){
                        sheet.shiftRows(13, sheet.getLastRowNum(), 10);//java.util.ConcurrentModificationException

                        //fill these cells just created
            }
        }
    }

Thank you.

Shankar
  • 2,890
  • 3
  • 25
  • 40
manuel_k
  • 575
  • 1
  • 8
  • 22
  • yOu are getting error because of sheet.shiftRows(13, sheet.getLastRowNum(), 10); Can you explain why you **13** - ? logic behind It. –  Oct 12 '17 at 12:53
  • because I want to shift row on that row number obviously – manuel_k Oct 12 '17 at 12:57
  • If your program don't find **13** then, https://stackoverflow.com/questions/42982531/shiftrows-apache-poi-3-9-sorting-sheet and https://stackoverflow.com/questions/24132601/apache-poi-shift-row –  Oct 12 '17 at 13:02
  • the program finds it because when I use the method outside the iterator it works great – manuel_k Oct 12 '17 at 13:04

0 Answers0