Top Description Inners Fields Constructors Methods
org.apache.poi.ss.util

public abstract Class CellRangeAddressBase

extends Object
implements Iterable<CellAddress>, Duplicatable, GenericRecord
Class Inheritance
All Implemented Interfaces
org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.common.Duplicatable, java.lang.Iterable
Known Direct Subclasses
org.apache.poi.hssf.util.CellRangeAddress8Bit, org.apache.poi.ss.util.CellRangeAddress
Imports
java.util.EnumSet, .Iterator, .Map, .NoSuchElementException, .Set, .Spliterator, .Spliterators, java.util.function.Supplier, org.apache.poi.common.Duplicatable, org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.ss.usermodel.Cell, org.apache.poi.util.GenericRecordUtil

See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'

Common superclass of 8-bit and 16-bit versions

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CellRangeAddressBase.CellPosition

Indicates a cell or range is in the given relative position in a range.

private static class
CellRangeAddressBase.RowMajorCellAddressIterator

Iterates over the cell addresses in a cell range in row major order The iterator is unaffected by changes to the CellRangeAddressBase instance after the iterator is created.

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private int

Constructor Summary

AccessConstructor and Description
protected
CellRangeAddressBase(int firstRow, int lastRow, int firstCol, int lastCol)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the range contains the column [colInd]
containsColumn
(int
the column to check
colInd
)

Check if the column is in the specified cell range

public boolean

Returns:

true if the range contains the row [rowInd]
containsRow
(int
the row to check
rowInd
)

Check if the row is in the specified cell range

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final int

Returns:

column number for the upper left hand corner
getFirstColumn
()

public final int

Returns:

row number for the upper left hand corner
getFirstRow
()

public Map<String, Supplier<?>>
public final int

Returns:

column number for the lower right hand corner
getLastColumn
()

public final int

Returns:

row number for the lower right hand corner
getLastRow
()

protected int
protected int
protected int
protected int
public int

Returns:

the size of the range (number of cells in the area).
getNumberOfCells
()

public Set<CellRangeAddressBase.CellPosition>

Returns:

set of CellPositions occupied by the given coordinates. Empty if the coordinates are not in the range, never null.
getPosition
(int rowInd, int colInd)

Useful for logic like table/range styling, where some elements apply based on relative position in a range.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

returns true if this range and other range have at least 1 cell in common
intersects
(CellRangeAddressBase
a candidate cell range address to check for intersection with this range
other
)

Determines whether or not this CellRangeAddress and the specified CellRangeAddress intersect.

public final boolean
public final boolean
public boolean

Returns:

True if the coordinates lie within the bounds, false otherwise.
isInRange
(int
The row, 0-based.
rowInd
,
int
The column, 0-based.
colInd
)

Determines if the given coordinates lie within the bounds of this range.

public boolean

Returns:

True if the reference lies within the bounds, false otherwise.
isInRange
(CellReference
the CellReference to check
ref
)

Determines if the given CellReference lies within the bounds of this range.

public boolean

Returns:

True if the reference lies within the bounds, false otherwise.
isInRange
(CellAddress
the CellAddress to check
ref
)

Determines if the given CellAddress lies within the bounds of this range.

public boolean

Returns:

True if the cell lies within the bounds, false otherwise.
isInRange
(Cell
the Cell to check
cell
)

Determines if the given Cell lies within the bounds of this range.

public Iterator<CellAddress>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over the CellAddresses in this cell range in row-major order.

public final void
setFirstColumn(int
column number for the upper left hand corner
firstCol
)

public final void
setFirstRow(int
row number for the upper left hand corner
firstRow
)

public final void
setLastColumn(int
column number for the lower right hand corner
lastCol
)

public final void
setLastRow(int
row number for the lower right hand corner
lastRow
)

public Spliterator<CellAddress>
spliterator()

Overrides default java.lang.Iterable.spliterator.

Returns a spliterator over the CellAddresses in this cell range in row-major order.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
validate(SpreadsheetVersion
the version of Excel to validate against
ssVersion
)

Validate the range limits against the supplied version of Excel

private static void
validateColumn(int column, SpreadsheetVersion ssVersion)

Runs a bounds check for column numbers

private static void
validateRow(int row, SpreadsheetVersion ssVersion)

Runs a bounds check for row numbers

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

_firstColback to summary
private int _firstCol
_firstRowback to summary
private int _firstRow
_lastColback to summary
private int _lastCol
_lastRowback to summary
private int _lastRow

Constructor Detail

CellRangeAddressBaseback to summary
protected CellRangeAddressBase(int firstRow, int lastRow, int firstCol, int lastCol)

Method Detail

containsColumnback to summary
public boolean containsColumn(int colInd)

Check if the column is in the specified cell range

Parameters
colInd:int

the column to check

Returns:boolean

true if the range contains the column [colInd]

containsRowback to summary
public boolean containsRow(int rowInd)

Check if the row is in the specified cell range

Parameters
rowInd:int

the row to check

Returns:boolean

true if the range contains the row [rowInd]

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getFirstColumnback to summary
public final int getFirstColumn()
Returns:int

column number for the upper left hand corner

getFirstRowback to summary
public final int getFirstRow()
Returns:int

row number for the upper left hand corner

getGenericPropertiesback to summary
public Map<String, Supplier<?>> getGenericProperties()

Implements org.apache.poi.common.usermodel.GenericRecord.getGenericProperties.

Annotations
@Override
getLastColumnback to summary
public final int getLastColumn()
Returns:int

column number for the lower right hand corner

getLastRowback to summary
public final int getLastRow()
Returns:int

row number for the lower right hand corner

getMaxColumnback to summary
protected int getMaxColumn()
getMaxRowback to summary
protected int getMaxRow()
getMinColumnback to summary
protected int getMinColumn()
getMinRowback to summary
protected int getMinRow()
getNumberOfCellsback to summary
public int getNumberOfCells()
Returns:int

the size of the range (number of cells in the area).

getPositionback to summary
public Set<CellRangeAddressBase.CellPosition> getPosition(int rowInd, int colInd)

Useful for logic like table/range styling, where some elements apply based on relative position in a range.

Returns:Set<CellRangeAddressBase.CellPosition>

set of CellPositions occupied by the given coordinates. Empty if the coordinates are not in the range, never null.

Since
3.17 beta 1
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
intersectsback to summary
public boolean intersects(CellRangeAddressBase other)

Determines whether or not this CellRangeAddress and the specified CellRangeAddress intersect.

Parameters
other:CellRangeAddressBase

a candidate cell range address to check for intersection with this range

Returns:boolean

returns true if this range and other range have at least 1 cell in common

See Also
for checking if a single cell intersects
isFullColumnRangeback to summary
public final boolean isFullColumnRange()
isFullRowRangeback to summary
public final boolean isFullRowRange()
isInRangeback to summary
public boolean isInRange(int rowInd, int colInd)

Determines if the given coordinates lie within the bounds of this range.

Parameters
rowInd:int

The row, 0-based.

colInd:int

The column, 0-based.

Returns:boolean

True if the coordinates lie within the bounds, false otherwise.

See Also
{@link #intersects(CellRangeAddressBase)} for checking if two ranges overlap
isInRangeback to summary
public boolean isInRange(CellReference ref)

Determines if the given CellReference lies within the bounds of this range.

Note

It is up to the caller to ensure the reference is for the correct sheet, since this instance doesn't have a sheet reference.

Parameters
ref:CellReference

the CellReference to check

Returns:boolean

True if the reference lies within the bounds, false otherwise.

See Also
{@link #intersects(CellRangeAddressBase)} for checking if two ranges overlap
isInRangeback to summary
public boolean isInRange(CellAddress ref)

Determines if the given CellAddress lies within the bounds of this range.

Note

It is up to the caller to ensure the reference is for the correct sheet, since this instance doesn't have a sheet reference.

Parameters
ref:CellAddress

the CellAddress to check

Returns:boolean

True if the reference lies within the bounds, false otherwise.

See Also
{@link #intersects(CellRangeAddressBase)} for checking if two ranges overlap
isInRangeback to summary
public boolean isInRange(Cell cell)

Determines if the given Cell lies within the bounds of this range.

Note

It is up to the caller to ensure the reference is for the correct sheet, since this instance doesn't have a sheet reference.

Parameters
cell:Cell

the Cell to check

Returns:boolean

True if the cell lies within the bounds, false otherwise.

See Also
{@link #intersects(CellRangeAddressBase)} for checking if two ranges overlap
iteratorback to summary
public Iterator<CellAddress> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over the CellAddresses in this cell range in row-major order.

Returns:Iterator<CellAddress>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
Since
POI 4.0.0
setFirstColumnback to summary
public final void setFirstColumn(int firstCol)
Parameters
firstCol:int

column number for the upper left hand corner

setFirstRowback to summary
public final void setFirstRow(int firstRow)
Parameters
firstRow:int

row number for the upper left hand corner

setLastColumnback to summary
public final void setLastColumn(int lastCol)
Parameters
lastCol:int

column number for the lower right hand corner

setLastRowback to summary
public final void setLastRow(int lastRow)
Parameters
lastRow:int

row number for the lower right hand corner

spliteratorback to summary
public Spliterator<CellAddress> spliterator()

Overrides default java.lang.Iterable.spliterator.

Returns a spliterator over the CellAddresses in this cell range in row-major order.

Returns:Spliterator<CellAddress>

Doc from java.lang.Iterable.spliterator.

a Spliterator over the elements described by this Iterable.

Annotations
@Override
Since
POI 5.2.0
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
validateback to summary
public void validate(SpreadsheetVersion ssVersion)

Validate the range limits against the supplied version of Excel

Parameters
ssVersion:SpreadsheetVersion

the version of Excel to validate against

Exceptions
IllegalArgumentException:
if the range limits are outside of the allowed range
validateColumnback to summary
private static void validateColumn(int column, SpreadsheetVersion ssVersion)

Runs a bounds check for column numbers

validateRowback to summary
private static void validateRow(int row, SpreadsheetVersion ssVersion)

Runs a bounds check for row numbers

org.apache.poi.ss.util back to summary

public final Enum CellRangeAddressBase.CellPosition

extends Enum<CellRangeAddressBase.CellPosition>
Class Inheritance

Indicates a cell or range is in the given relative position in a range. More than one of these may apply at once.

Field Summary

Modifier and TypeField and Description
public static final CellRangeAddressBase.CellPosition
BOTTOM

range ending rows are equal

public static final CellRangeAddressBase.CellPosition
INSIDE

a cell or range is completely inside another range, without touching any edges (a cell in this position can't be in any others)

public static final CellRangeAddressBase.CellPosition
LEFT

range starting columns are equal

public static final CellRangeAddressBase.CellPosition
RIGHT

range ending columns are equal

public static final CellRangeAddressBase.CellPosition
TOP

range starting rows are equal

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CellRangeAddressBase.CellPosition
public static CellRangeAddressBase.CellPosition[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BOTTOMback to summary
public static final CellRangeAddressBase.CellPosition BOTTOM

range ending rows are equal

INSIDEback to summary
public static final CellRangeAddressBase.CellPosition INSIDE

a cell or range is completely inside another range, without touching any edges (a cell in this position can't be in any others)

LEFTback to summary
public static final CellRangeAddressBase.CellPosition LEFT

range starting columns are equal

RIGHTback to summary
public static final CellRangeAddressBase.CellPosition RIGHT

range ending columns are equal

TOPback to summary
public static final CellRangeAddressBase.CellPosition TOP

range starting rows are equal

Constructor Detail

CellPositionback to summary
private CellPosition()

Method Detail

valueOfback to summary
public static CellRangeAddressBase.CellPosition valueOf(String name)
valuesback to summary
public static CellRangeAddressBase.CellPosition[] values()
org.apache.poi.ss.util back to summary

private Class CellRangeAddressBase.RowMajorCellAddressIterator

extends Object
implements Iterator<CellAddress>
Class Inheritance
  • java.lang.Object
  • org.apache.poi.ss.util.CellRangeAddressBase.RowMajorCellAddressIterator
All Implemented Interfaces
java.util.Iterator

Iterates over the cell addresses in a cell range in row major order The iterator is unaffected by changes to the CellRangeAddressBase instance after the iterator is created.

Field Summary

Modifier and TypeField and Description
private int
c

private final int
private final int
private final int
private final int
private int
r

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public CellAddress
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cback to summary
private int c
firstColback to summary
private final int firstCol
firstRowback to summary
private final int firstRow
lastColback to summary
private final int lastCol
lastRowback to summary
private final int lastRow
rback to summary
private int r

Constructor Detail

RowMajorCellAddressIteratorback to summary
public RowMajorCellAddressIterator(CellRangeAddressBase ref)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public CellAddress next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:CellAddress

the next element in the iteration

Annotations
@Override