Top Description Inners Methods
org.apache.poi.ss.usermodel

public Interface Row

extends Iterable<Cell>
Known Direct Implementers
org.apache.poi.hssf.usermodel.HSSFRow
Imports
java.util.Iterator, .Spliterator, .Spliterators

High level representation of a row of a spreadsheet.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Row.MissingCellPolicy

Used to specify the different possible policies if for the case of null and blank cells

Method Summary

Modifier and TypeMethod and Description
public Iterator<Cell>

Returns:

Cell iterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!
cellIterator
()

public Cell

Returns:

Cell a high level representation of the created cell.
createCell
(int
- the column number this cell represents
column
)

Use this to create new cells within the row and return it.

public Cell

Returns:

Cell a high level representation of the created cell.
createCell
(int
- the column number this cell represents
column
,
CellType
- the cell's data type
type
)

Use this to create new cells within the row and return it.

public Cell

Returns:

Cell representing that column or null if undefined.
getCell
(int
0 based column number
cellnum
)

Get the cell representing a given column (logical cell) 0-based.

public Cell

Returns:

the cell at the given (0 based) index
getCell
(int cellnum, Row.MissingCellPolicy policy)

Returns the cell at the given (0 based) index, with the specified org.apache.poi.ss.usermodel.Row.MissingCellPolicy

public short

Returns:

short representing the first logical cell in the row, or -1 if the row does not contain any cells.
getFirstCellNum
()

Get the number of the first cell contained in this row.

public short

Returns:

row height measured in twips (1/20th of a point)
getHeight
()

Get the row's height measured in twips (1/20th of a point).

public float

Returns:

row height measured in point size
getHeightInPoints
()

Returns row height measured in point size.

public short

Returns:

short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.
getLastCellNum
()

Gets the index of the last cell contained in this row PLUS ONE.

public int
getOutlineLevel()

Returns the rows outline level.

public int

Returns:

int representing the number of defined cells in the row.
getPhysicalNumberOfCells
()

Gets the number of defined cells (NOT number of cells in the actual row!).

public int

Returns:

the row number (0 based)
getRowNum
()

Get row number this row represents

public CellStyle
getRowStyle()

Returns the whole-row cell styles.

public Sheet

Returns:

the Sheet that owns this row
getSheet
()

Returns the Sheet this row belongs to

public boolean

Returns:

- zHeight height is zero or not.
getZeroHeight
()

Get whether or not to display this row with 0 height

public boolean
isFormatted()

Is this row formatted?

public default Iterator<Cell>

Returns:

an iterator over cells in this row.
iterator
()

Implements java.lang.Iterable.iterator.

Alias for cellIterator() to allow foreach loops:

for(Cell cell : row){
    ...
}
public void
removeCell(Cell
the cell to remove
cell
)

Remove the Cell from this row.

public void
setHeight(short
rowheight or 0xff for undefined (use sheet default)
height
)

Set the row's height or set to ff (-1) for undefined/default-height.

public void
setHeightInPoints(float
the height in points. -1 resets to the default height
height
)

Set the row's height in points.

public void
setRowNum(int
the row number (0-based)
rowNum
)

Set the row number of this row.

public void
setRowStyle(CellStyle style)

Applies a whole-row cell styling to the row.

public void
setZeroHeight(boolean
height is zero or not.
zHeight
)

Set whether or not to display this row with 0 height

public void
shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)

public void
shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)

public default Spliterator<Cell>

Returns:

Cell spliterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!
spliterator
()

Overrides default java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

Inherited from java.lang.Iterable:
forEach

Method Detail

cellIteratorback to summary
public Iterator<Cell> cellIterator()
Returns:Iterator<Cell>

Cell iterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!

createCellback to summary
public Cell createCell(int column)

Use this to create new cells within the row and return it.

The cell that is returned is a CellType#BLANK. The type can be changed either through calling setCellValue or setCellType.

Parameters
column:int

- the column number this cell represents

Returns:Cell

Cell a high level representation of the created cell.

Exceptions
IllegalArgumentException:
if columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
createCellback to summary
public Cell createCell(int column, CellType type)

Use this to create new cells within the row and return it.

The cell that is returned will be of the requested type. The type can be changed either through calling setCellValue or setCellType, but there is a small overhead to doing this, so it is best to create of the required type up front.

Parameters
column:int

- the column number this cell represents

type:CellType

- the cell's data type

Returns:Cell

Cell a high level representation of the created cell.

Exceptions
IllegalArgumentException:
if columnIndex < 0 or greater than a maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
getCellback to summary
public Cell getCell(int cellnum)

Get the cell representing a given column (logical cell) 0-based. If you ask for a cell that is not defined....you get a null.

Parameters
cellnum:int

0 based column number

Returns:Cell

Cell representing that column or null if undefined.

See Also
getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
getCellback to summary
public Cell getCell(int cellnum, Row.MissingCellPolicy policy)

Returns the cell at the given (0 based) index, with the specified org.apache.poi.ss.usermodel.Row.MissingCellPolicy

Returns:Cell

the cell at the given (0 based) index

Exceptions
IllegalArgumentException:
if cellnum < 0 or the specified MissingCellPolicy is invalid
getFirstCellNumback to summary
public short getFirstCellNum()

Get the number of the first cell contained in this row.

Note

cells which had content before and were set to empty later might still be counted as cells by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be lower than expected!

Returns:short

short representing the first logical cell in the row, or -1 if the row does not contain any cells.

getHeightback to summary
public short getHeight()

Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned, See Sheet#getDefaultRowHeightInPoints()

Returns:short

row height measured in twips (1/20th of a point)

getHeightInPointsback to summary
public float getHeightInPoints()

Returns row height measured in point size. If the height is not set, the default worksheet value is returned, See Sheet#getDefaultRowHeightInPoints()

Returns:float

row height measured in point size

See Also
Sheet#getDefaultRowHeightInPoints()
getLastCellNumback to summary
public short getLastCellNum()

Gets the index of the last cell contained in this row PLUS ONE. The result also happens to be the 1-based column number of the last cell. This value can be used as a standard upper bound when iterating over cells:

short minColIx = row.getFirstCellNum();
short maxColIx = row.getLastCellNum();
for(short colIx=minColIx; colIx<maxColIx; colIx++) {
  Cell cell = row.getCell(colIx);
  if(cell == null) {
    continue;
  }
  //... do something with cell
}
Note: cells which had content before and were set to empty later might still be counted as cells by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be higher than expected!
Returns:short

short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.

getOutlineLevelback to summary
public int getOutlineLevel()

Returns the rows outline level. Increased as you put it into more groups (outlines), reduced as you take it out of them.

getPhysicalNumberOfCellsback to summary
public int getPhysicalNumberOfCells()

Gets the number of defined cells (NOT number of cells in the actual row!). That is to say if only columns 0,4,5 have values then there would be 3.

Returns:int

int representing the number of defined cells in the row.

getRowNumback to summary
public int getRowNum()

Get row number this row represents

Returns:int

the row number (0 based)

getRowStyleback to summary
public CellStyle getRowStyle()

Returns the whole-row cell styles. Most rows won't have one of these, so will return null. Call isFormatted() to check first.

getSheetback to summary
public Sheet getSheet()

Returns the Sheet this row belongs to

Returns:Sheet

the Sheet that owns this row

getZeroHeightback to summary
public boolean getZeroHeight()

Get whether or not to display this row with 0 height

Returns:boolean

- zHeight height is zero or not.

isFormattedback to summary
public boolean isFormatted()

Is this row formatted? Most aren't, but some rows do have whole-row styles. For those that do, you can get the formatting from getRowStyle()

iteratorback to summary
public default Iterator<Cell> iterator()

Implements java.lang.Iterable.iterator.

Alias for cellIterator() to allow foreach loops:

for(Cell cell : row){
    ...
}
Returns:Iterator<Cell>

an iterator over cells in this row.

Annotations
@Override
removeCellback to summary
public void removeCell(Cell cell)

Remove the Cell from this row.

Parameters
cell:Cell

the cell to remove

setHeightback to summary
public void setHeight(short height)

Set the row's height or set to ff (-1) for undefined/default-height. Set the height in "twips" or 1/20th of a point.

Parameters
height:short

rowheight or 0xff for undefined (use sheet default)

setHeightInPointsback to summary
public void setHeightInPoints(float height)

Set the row's height in points.

Parameters
height:float

the height in points. -1 resets to the default height

setRowNumback to summary
public void setRowNum(int rowNum)

Set the row number of this row.

Parameters
rowNum:int

the row number (0-based)

Exceptions
IllegalArgumentException:
if rowNum < 0
setRowStyleback to summary
public void setRowStyle(CellStyle style)

Applies a whole-row cell styling to the row.

setZeroHeightback to summary
public void setZeroHeight(boolean zHeight)

Set whether or not to display this row with 0 height

Parameters
zHeight:boolean

height is zero or not.

shiftCellsLeftback to summary
public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
shiftCellsRightback to summary
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
spliteratorback to summary
public default Spliterator<Cell> spliterator()

Overrides default java.lang.Iterable.spliterator.

Doc from java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

Returns:Spliterator<Cell>

Cell spliterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!

Annotations
@Override
Since
POI 5.2.0
org.apache.poi.ss.usermodel back to summary

public final Enum Row.MissingCellPolicy

extends Enum<Row.MissingCellPolicy>
Class Inheritance

Used to specify the different possible policies if for the case of null and blank cells

Field Summary

Modifier and TypeField and Description
public static final Row.MissingCellPolicy
public static final Row.MissingCellPolicy
public static final Row.MissingCellPolicy

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CREATE_NULL_AS_BLANKback to summary
public static final Row.MissingCellPolicy CREATE_NULL_AS_BLANK
RETURN_BLANK_AS_NULLback to summary
public static final Row.MissingCellPolicy RETURN_BLANK_AS_NULL
RETURN_NULL_AND_BLANKback to summary
public static final Row.MissingCellPolicy RETURN_NULL_AND_BLANK

Constructor Detail

MissingCellPolicyback to summary
private MissingCellPolicy()

Method Detail

valueOfback to summary
public static Row.MissingCellPolicy valueOf(String name)
valuesback to summary
public static Row.MissingCellPolicy[] values()