diff options
Diffstat (limited to 'src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java')
-rw-r--r-- | src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java | 109 |
1 files changed, 54 insertions, 55 deletions
diff --git a/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java b/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java index 53e21640cf..4efd80d60c 100644 --- a/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java +++ b/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java @@ -17,12 +17,10 @@ package org.apache.poi.ss.util.cellwalk; - import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.DataMarker; /** * Traverse cell range. @@ -35,95 +33,96 @@ public class CellWalk { private CellRangeAddress range; private boolean traverseEmptyCells; - public CellWalk(DataMarker dm) { - this(dm.getSheet(), dm.getRange()); - } public CellWalk(Sheet sheet, CellRangeAddress range) { - this.sheet = sheet; - this.range = range; - this.traverseEmptyCells = false; + this.sheet = sheet; + this.range = range; + this.traverseEmptyCells = false; } /** * Should we call handler on empty (blank) cells. Default is * false. + * * @return true if handler should be called on empty (blank) - * cells, false otherwise. + * cells, false otherwise. */ public boolean isTraverseEmptyCells() { - return traverseEmptyCells; + return traverseEmptyCells; } /** * Sets the traverseEmptyCells property. + * * @param traverseEmptyCells new property value */ public void setTraverseEmptyCells(boolean traverseEmptyCells) { - this.traverseEmptyCells = traverseEmptyCells; + this.traverseEmptyCells = traverseEmptyCells; } /** * Traverse cell range from top left to bottom right cell. + * * @param handler handler to call on each appropriate cell */ public void traverse(CellHandler handler) { - int firstRow = range.getFirstRow(); - int lastRow = range.getLastRow(); - int firstColumn = range.getFirstColumn(); - int lastColumn = range.getLastColumn(); - final int width = lastColumn - firstColumn + 1; - SimpleCellWalkContext ctx = new SimpleCellWalkContext(); - Row currentRow = null; - Cell currentCell = null; - - for (ctx.rowNumber = firstRow; ctx.rowNumber <= lastRow; ++ctx.rowNumber) { - currentRow = sheet.getRow(ctx.rowNumber); - if (currentRow == null) { - continue; - } - for (ctx.colNumber = firstColumn; ctx.colNumber <= lastColumn; ++ctx.colNumber) { - currentCell = currentRow.getCell(ctx.colNumber); - - if (currentCell == null) { - continue; - } - if (isEmpty(currentCell) && !traverseEmptyCells) { - continue; - } - - ctx.ordinalNumber = - (ctx.rowNumber - firstRow) * width + - (ctx.colNumber - firstColumn + 1); - - handler.onCell(currentCell, ctx); - } - } + int firstRow = range.getFirstRow(); + int lastRow = range.getLastRow(); + int firstColumn = range.getFirstColumn(); + int lastColumn = range.getLastColumn(); + final int width = lastColumn - firstColumn + 1; + SimpleCellWalkContext ctx = new SimpleCellWalkContext(); + Row currentRow = null; + Cell currentCell = null; + + for (ctx.rowNumber = firstRow; ctx.rowNumber <= lastRow; ++ctx.rowNumber) { + currentRow = sheet.getRow(ctx.rowNumber); + if (currentRow == null) { + continue; + } + for (ctx.colNumber = firstColumn; ctx.colNumber <= lastColumn; ++ctx.colNumber) { + currentCell = currentRow.getCell(ctx.colNumber); + + if (currentCell == null) { + continue; + } + if (isEmpty(currentCell) && !traverseEmptyCells) { + continue; + } + + ctx.ordinalNumber = + (ctx.rowNumber - firstRow) * width + + (ctx.colNumber - firstColumn + 1); + + handler.onCell(currentCell, ctx); + } + } } private boolean isEmpty(Cell cell) { - return (cell.getCellType() == Cell.CELL_TYPE_BLANK); + return (cell.getCellType() == Cell.CELL_TYPE_BLANK); } /** * Inner class to hold walk context. + * * @author Roman Kashitsyn */ private class SimpleCellWalkContext implements CellWalkContext { - public long ordinalNumber = 0; - public int rowNumber = 0; - public int colNumber = 0; + public long ordinalNumber = 0; + public int rowNumber = 0; + public int colNumber = 0; - public long getOrdinalNumber() { - return ordinalNumber; - } + public long getOrdinalNumber() { + return ordinalNumber; + } - public int getRowNumber() { - return rowNumber; - } + public int getRowNumber() { + return rowNumber; + } - public int getColumnNumber() { - return colNumber; - } + public int getColumnNumber() { + return colNumber; + } } } |