我有100行10列。逐一读取每行和列。在第10列之后,光标不会移动到下一行。它将进入11,12,13等栏目。谁能帮我在读到第10列时如何移动下一行,以及如何停止读空11列。
下面是一些代码:
while (rowIterator.hasNext()) {
row = rowIterator.next();
while (cellIterator.hasNext()) {
cell = cellIterator.next();
if(cell.getColumnIndex()==0 ) { }
.....
if(cell.getColumnIndex()==10) { }
}
}发布于 2016-12-22 22:05:27
首先,这不一定能解决你的问题,你应该使用for each语法来迭代行和列,然后一旦你通过了第10列,你就可以像这样跳出循环:
for (Row row : sheet){
for (Cell cell : row) {
...
if (cell.getColumnIndex() >= 10) break;
}
}这在以下位置的POI快速指南中进行了记录:https://poi.apache.org/spreadsheet/quick-guide.html#Iterator
注意:当列索引为10或更大(这将是第11列,因为索引基于0)时,我会中断。我之所以提到这一点,只是因为您的代码示例使用了列索引0- 10,但您的文本中只有10个有效列。
https://stackoverflow.com/questions/41276799
复制相似问题