Package org.apache.poi.hssf.usermodel
Class HSSFRow
java.lang.Object
org.apache.poi.hssf.usermodel.HSSFRow
- All Implemented Interfaces:
Comparable<HSSFRow>
,Iterable<Cell>
,Row
High level representation of a row of a spreadsheet.
Only rows that have cells should be added to a Sheet.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.poi.ss.usermodel.Row
Row.MissingCellPolicy
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionint
Compares twoHSSFRow
objects.createCell
(int column) Use this to create new cells within the row and return it.createCell
(int columnIndex, CellType type) Use this to create new cells within the row and return it.boolean
getCell
(int cellnum) Get the hssfcell representing a given column (logical cell) 0-based.getCell
(int cellnum, Row.MissingCellPolicy policy) Get the hssfcell representing a given column (logical cell) 0-based.short
get the number of the first cell contained in this row.short
get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)float
get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())short
Gets the index of the last cell contained in this row PLUS ONE.int
Returns the rows outline level.int
gets the number of defined cells (NOT number of cells in the actual row!).int
get row number this row representsprotected RowRecord
get the lowlevel RowRecord represented by this object - should only be called by other parts of the high level APIReturns the whole-row cell styles.getSheet()
Returns the HSSFSheet this row belongs toboolean
get whether or not to display this row with 0 heightint
hashCode()
boolean
Is this row formatted? Most aren't, but some rows do have whole-row styles.iterator()
Alias forcellIterator()
to allow foreach loopsvoid
Moves the supplied cell to a new column, which must not already have a cell there!protected void
Removes all the cells from the row, and their records too.void
removeCell
(Cell cell) remove the HSSFCell from this row.void
setHeight
(short height) set the row's height or set to ff (-1) for undefined/default-height.void
setHeightInPoints
(float height) set the row's height in points.void
setRowNum
(int rowIndex) set the row number of this row.void
setRowStyle
(HSSFCellStyle style) Applies a whole-row cell styling to the row.void
setRowStyle
(CellStyle style) Applies a whole-row cell styling to the row.void
setZeroHeight
(boolean zHeight) set whether or not to display this row with 0 heightvoid
shiftCellsLeft
(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.void
shiftCellsRight
(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
INITIAL_CAPACITY
public static final int INITIAL_CAPACITY
-
-
Method Details
-
createCell
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 callingsetCellValue
orsetCellType
.- Specified by:
createCell
in interfaceRow
- Parameters:
column
- - the column number this cell represents- Returns:
- HSSFCell a high level representation of the created cell.
- Throws:
IllegalArgumentException
- if columnIndex < 0 or greater than 255, the maximum number of columns supported by the Excel binary format (.xls)
-
createCell
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 the required type up front.
- Specified by:
createCell
in interfaceRow
- Parameters:
columnIndex
- - the column number this cell representstype
- - the cell's data type- Returns:
- HSSFCell a high level representation of the created cell.
- Throws:
IllegalArgumentException
- if columnIndex < 0 or greater than 255, the maximum number of columns supported by the Excel binary format (.xls)
-
removeCell
remove the HSSFCell from this row.- Specified by:
removeCell
in interfaceRow
- Parameters:
cell
- to remove
-
removeAllCells
protected void removeAllCells()Removes all the cells from the row, and their records too. -
setRowNum
public void setRowNum(int rowIndex) set the row number of this row.- Specified by:
setRowNum
in interfaceRow
- Parameters:
rowIndex
- the row number (0-based)- Throws:
IndexOutOfBoundsException
- if the row number is not within the range 0-65535.
-
getRowNum
public int getRowNum()get row number this row represents -
getSheet
Returns the HSSFSheet this row belongs to -
getOutlineLevel
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.- Specified by:
getOutlineLevel
in interfaceRow
-
moveCell
Moves the supplied cell to a new column, which must not already have a cell there!- Parameters:
cell
- The cell to movenewColumn
- The new column number (0 based)
-
getCell
Get the hssfcell representing a given column (logical cell) 0-based. If you ask for a cell that is not defined then you get a null, unless you have set a differentRow.MissingCellPolicy
on the base workbook. -
getCell
Get the hssfcell representing a given column (logical cell) 0-based. If you ask for a cell that is not defined, then your supplied policy says what to do -
getFirstCellNum
public short getFirstCellNum()get the number of the first cell contained in this row.- Specified by:
getFirstCellNum
in interfaceRow
- Returns:
- short representing the first logical cell in the row, or -1 if the row does not contain any cells.
-
getLastCellNum
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++) { HSSFCell cell = row.getCell(colIx); if(cell == null) { continue; } //... do something with cell }
- Specified by:
getLastCellNum
in interfaceRow
- Returns:
- short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.
-
getPhysicalNumberOfCells
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.- Specified by:
getPhysicalNumberOfCells
in interfaceRow
- Returns:
- int representing the number of defined cells in the row.
-
setHeight
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. -
setZeroHeight
public void setZeroHeight(boolean zHeight) set whether or not to display this row with 0 height- Specified by:
setZeroHeight
in interfaceRow
- Parameters:
zHeight
- height is zero or not.
-
getZeroHeight
public boolean getZeroHeight()get whether or not to display this row with 0 height- Specified by:
getZeroHeight
in interfaceRow
- Returns:
- - zHeight height is zero or not.
-
setHeightInPoints
public void setHeightInPoints(float height) set the row's height in points.- Specified by:
setHeightInPoints
in interfaceRow
- Parameters:
height
- row height in points,-1
means to use the default height
-
getHeight
public short getHeight()get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point) -
getHeightInPoints
public float getHeightInPoints()get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())- Specified by:
getHeightInPoints
in interfaceRow
- Returns:
- rowheight or 0xff for undefined (use sheet default)
- See Also:
-
getRowRecord
get the lowlevel RowRecord represented by this object - should only be called by other parts of the high level API- Returns:
- RowRecord this row represents
-
isFormatted
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 fromgetRowStyle()
- Specified by:
isFormatted
in interfaceRow
-
getRowStyle
Returns the whole-row cell styles. Most rows won't have one of these, so will return null. CallisFormatted()
to check first.- Specified by:
getRowStyle
in interfaceRow
-
setRowStyle
Applies a whole-row cell styling to the row. -
setRowStyle
Applies a whole-row cell styling to the row.- Specified by:
setRowStyle
in interfaceRow
-
cellIterator
- Specified by:
cellIterator
in interfaceRow
- Returns:
- cell iterator of the physically defined cells.
Note that the 4th element might well not be cell 4, as the iterator
will not return un-defined (null) cells.
Call getCellNum() on the returned cells to know which cell they are.
As this only ever works on physically defined cells,
the
Row.MissingCellPolicy
has no effect.
-
iterator
Alias forcellIterator()
to allow foreach loops -
compareTo
Compares twoHSSFRow
objects. Two rows are equal if they belong to the same worksheet and their row indexes are equal.- Specified by:
compareTo
in interfaceComparable<HSSFRow>
- Parameters:
other
- theHSSFRow
to be compared.- Returns:
-
the value
0
if the row number of thisHSSFRow
is equal to the row number of the argumentHSSFRow
-
a value less than
0
if the row number of this thisHSSFRow
is numerically less than the row number of the argumentHSSFRow
-
a value greater than
0
if the row number of this thisHSSFRow
is numerically greater than the row number of the argumentHSSFRow
-
the value
- Throws:
IllegalArgumentException
- if the argument row belongs to a different worksheet
-
equals
-
hashCode
public int hashCode() -
shiftCellsRight
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.- Specified by:
shiftCellsRight
in interfaceRow
- Parameters:
firstShiftColumnIndex
- the column to start shiftinglastShiftColumnIndex
- the column to end shiftingstep
- length of the shifting step
-
shiftCellsLeft
public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.- Specified by:
shiftCellsLeft
in interfaceRow
- Parameters:
firstShiftColumnIndex
- the column to start shiftinglastShiftColumnIndex
- the column to end shiftingstep
- length of the shifting step
-