![](/img/trans.png)
[英]Java apache POI - How do I do, in word using poi, every page has borders?
[英]How do I stop iteration in Java using Apache POI
我正在使用Apache POI阅读Java中的特定excel模板。 底部有一些不需要的字段(例如小指南),我需要跳过。 所以我想在POI发现一行完全空白时停止迭代,因此底部的字段将被自动跳过。
我发现了许多处理空白CELL的方法,但我的要求是完整行。
以下代码将遍历一行的单元格。 它将为每个遇到的单元格保留一个计数(cellCount)。 仅当单元格为空白时,另一个couont(nullCount)才增加。 如果这两个计数相等,则行为空。
boolean isEmptyRow = false;
int cellCount = 0;
int nullCount = 0;
Iterator<Cell> cellIterator = row.iterator();
while (cellIterator.hasNext()) {
cellCount++;
Cell cell = (Cell) cellIterator.next();
if ((cell == null)
|| ((cell != null) && (cell.getCellType() == Cell.CELL_TYPE_BLANK))) {
nullCount++;
}
}
if ((cellCount != 0) && (nullCount != 0)
&& (cellCount == nullCount)) { //If nullCount & cellCouont are same, Row is empty
isEmptyRow = true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.