![](/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.