Free Support Forum - aspose.com

Cell iterator throws NoSuchElementException

Hello,

i’ve got this piece of code:

Iterator rowIter = cellsBlabla.getCell(“A10”).getCells().getRowIterator();

Set listOfStrings = someObject.getListOfStrings();

Row actualRow = rowIter.next();

for(String str : listOfStrings) {

Cell actualCell;
Iterator cellIter = actualRow.getCellIterator();

actualCell = cellIter.next()
actualCell.setValue(str);

actualCell = cellIter.next()

actualCell.setValue(str + “bla”);


// next line…
actualRow = rowIter.next();
}


1) first call of rowIter.next() doesn’t star at “A10” cell but on the first cell, which is weird because then
next call of rowIter.next() is on the right row (10th row)

what is wrong with my code? how can I easily get row iterator starting at some row number which I explicitly set?

2) consider second “for each” loop… second call of callIter.next() (where callIter is iterator for cells) throw an NoSuchElementException … why? I couldn’t be on the last cell in the row. What NoSuchElementException indicates in this case?

Hi,

We will check and get back to you soon.

Thank you.

Hi,

1.Cells.getRowIterator() is for getting all defined rows in a worksheet. To get row iterator starting at some row number, you can use the method Cells.getRowIterator(int startRowIndex). For more detail, please refer to the java-doc.

2.For the NoSuchElementException, commonly it is caused by having no enough items for the next() method call. If you are sure there are enough data, for you case in loop, at least 2 defined cells per row, please give us your template file and code, we will check and figure the issue out, thank you.