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
 
 public final class HSSFRow extends Object implements Row, Comparable<HSSFRow> 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.RowRow.MissingCellPolicy
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static intINITIAL_CAPACITY
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<Cell>cellIterator()intcompareTo(HSSFRow other)Compares twoHSSFRowobjects.voidcopyRowFrom(Row srcRow, CellCopyPolicy policy)Copy the cells from srcRow to this row If this row is not a blank row, this will merge the two rows, overwriting the cells in this row with the cells in srcRow If srcRow is null, overwrite cells in destination row with blank values, styles, etc per cell copy policy srcRow may be from a different sheet in the same workbookvoidcopyRowFrom(Row srcRow, CellCopyPolicy policy, CellCopyContext context)Copy the cells from srcRow to this row.HSSFCellcreateCell(int column)Use this to create new cells within the row and return it.HSSFCellcreateCell(int columnIndex, CellType type)Use this to create new cells within the row and return it.booleanequals(Object obj)HSSFCellgetCell(int cellnum)Get the hssfcell representing a given column (logical cell) 0-based.HSSFCellgetCell(int cellnum, Row.MissingCellPolicy policy)Get the hssfcell representing a given column (logical cell) 0-based.shortgetFirstCellNum()get the number of the first cell contained in this row.shortgetHeight()get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)floatgetHeightInPoints()get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())shortgetLastCellNum()Gets the index of the last cell contained in this row PLUS ONE.intgetOutlineLevel()Returns the rows outline level.intgetPhysicalNumberOfCells()gets the number of defined cells (NOT number of cells in the actual row!).intgetRowNum()get row number this row representsprotected RowRecordgetRowRecord()get the lowlevel RowRecord represented by this object - should only be called by other parts of the high level APIHSSFCellStylegetRowStyle()Returns the whole-row cell styles.HSSFSheetgetSheet()Returns the HSSFSheet this row belongs tobooleangetZeroHeight()get whether or not to display this row with 0 heightinthashCode()booleanisCustomHeight()booleanisFormatted()Is this row formatted? Most aren't, but some rows do have whole-row styles.voidmoveCell(HSSFCell cell, short newColumn)Moves the supplied cell to a new column, which must not already have a cell there!protected voidremoveAllCells()Removes all the cells from the row, and their records too.voidremoveCell(Cell cell)remove the HSSFCell from this row.voidsetCustomHeight(boolean b)voidsetHeight(short height)set the row's height or set to ff (-1) for undefined/default-height.voidsetHeightInPoints(float height)set the row's height in points.voidsetRowNum(int rowIndex)set the row number of this row.voidsetRowStyle(HSSFCellStyle style)Applies a whole-row cell styling to the row.voidsetRowStyle(CellStyle style)Applies a whole-row cell styling to the row.voidsetZeroHeight(boolean zHeight)set whether or not to display this row with 0 heightvoidshiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.voidshiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.- 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.poi.ss.usermodel.Rowiterator, spliterator
 
- 
 
- 
- 
- 
Method Detail- 
createCellpublic HSSFCell 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 callingsetCellValueorsetCellType.- Specified by:
- createCellin interface- Row
- 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)
 
 - 
createCellpublic HSSFCell createCell(int columnIndex, 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 the required type up front. - Specified by:
- createCellin interface- Row
- Parameters:
- columnIndex- - the column number this cell represents
- type- - 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)
 
 - 
removeCellpublic void removeCell(Cell cell) remove the HSSFCell from this row.- Specified by:
- removeCellin interface- Row
- Parameters:
- cell- to remove
 
 - 
removeAllCellsprotected void removeAllCells() Removes all the cells from the row, and their records too.
 - 
setRowNumpublic void setRowNum(int rowIndex) set the row number of this row.- Specified by:
- setRowNumin interface- Row
- Parameters:
- rowIndex- the row number (0-based)
- Throws:
- IndexOutOfBoundsException- if the row number is not within the range 0-65535.
 
 - 
getRowNumpublic int getRowNum() get row number this row represents
 - 
getSheetpublic HSSFSheet getSheet() Returns the HSSFSheet this row belongs to
 - 
getOutlineLevelpublic 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:
- getOutlineLevelin interface- Row
 
 - 
moveCellpublic void moveCell(HSSFCell cell, short newColumn) Moves the supplied cell to a new column, which must not already have a cell there!- Parameters:
- cell- The cell to move
- newColumn- The new column number (0 based)
 
 - 
getCellpublic HSSFCell getCell(int cellnum) 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.MissingCellPolicyon the base workbook.- Specified by:
- getCellin interface- Row
- Parameters:
- cellnum- 0 based column number
- Returns:
- HSSFCell representing that column or null if undefined.
- See Also:
- Row.getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
 
 - 
getCellpublic HSSFCell getCell(int cellnum, Row.MissingCellPolicy policy) 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
 - 
getFirstCellNumpublic short getFirstCellNum() get the number of the first cell contained in this row.- Specified by:
- getFirstCellNumin interface- Row
- Returns:
- short representing the first logical cell in the row, or -1 if the row does not contain any cells.
 
 - 
getLastCellNumpublic 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:
- getLastCellNumin interface- Row
- Returns:
- short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.
 
 - 
getPhysicalNumberOfCellspublic 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:
- getPhysicalNumberOfCellsin interface- Row
- Returns:
- int representing the number of defined cells in the row.
 
 - 
setHeightpublic 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.
 - 
setZeroHeightpublic void setZeroHeight(boolean zHeight) set whether or not to display this row with 0 height- Specified by:
- setZeroHeightin interface- Row
- Parameters:
- zHeight- height is zero or not.
 
 - 
getZeroHeightpublic boolean getZeroHeight() get whether or not to display this row with 0 height- Specified by:
- getZeroHeightin interface- Row
- Returns:
- - zHeight height is zero or not.
 
 - 
setHeightInPointspublic void setHeightInPoints(float height) set the row's height in points.- Specified by:
- setHeightInPointsin interface- Row
- Parameters:
- height- row height in points,- -1means to use the default height
 
 - 
getHeightpublic short getHeight() get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)
 - 
getHeightInPointspublic float getHeightInPoints() get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())- Specified by:
- getHeightInPointsin interface- Row
- Returns:
- rowheight or 0xff for undefined (use sheet default)
- See Also:
- Sheet.getDefaultRowHeightInPoints()
 
 - 
getRowRecordprotected RowRecord 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
 
 - 
isFormattedpublic 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:
- isFormattedin interface- Row
 
 - 
getRowStylepublic HSSFCellStyle 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:
- getRowStylein interface- Row
 
 - 
setRowStylepublic void setRowStyle(HSSFCellStyle style) Applies a whole-row cell styling to the row.
 - 
setRowStylepublic void setRowStyle(CellStyle style) Applies a whole-row cell styling to the row.- Specified by:
- setRowStylein interface- Row
 
 - 
cellIteratorpublic Iterator<Cell> cellIterator() - Specified by:
- cellIteratorin interface- Row
- 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.MissingCellPolicyhas no effect.
 
 - 
compareTopublic int compareTo(HSSFRow other) Compares twoHSSFRowobjects. Two rows are equal if they belong to the same worksheet and their row indexes are equal.- Specified by:
- compareToin interface- Comparable<HSSFRow>
- Parameters:
- other- the- HSSFRowto be compared.
- Returns:
- 
      the value 0if the row number of thisHSSFRowis equal to the row number of the argumentHSSFRow
- 
      a value less than 0if the row number of thisHSSFRowis numerically less than the row number of the argumentHSSFRow
- 
      a value greater than 0if the row number of thisHSSFRowis numerically greater than the row number of the argumentHSSFRow
 
- 
      the value 
- Throws:
- IllegalArgumentException- if the argument row belongs to a different worksheet
 
 - 
shiftCellsRightpublic void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.- Specified by:
- shiftCellsRightin interface- Row
- Parameters:
- firstShiftColumnIndex- the column to start shifting
- lastShiftColumnIndex- the column to end shifting
- step- length of the shifting step
 
 - 
shiftCellsLeftpublic void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.- Specified by:
- shiftCellsLeftin interface- Row
- Parameters:
- firstShiftColumnIndex- the column to start shifting
- lastShiftColumnIndex- the column to end shifting
- step- length of the shifting step
 
 - 
copyRowFrom@Beta public void copyRowFrom(Row srcRow, CellCopyPolicy policy) Copy the cells from srcRow to this row If this row is not a blank row, this will merge the two rows, overwriting the cells in this row with the cells in srcRow If srcRow is null, overwrite cells in destination row with blank values, styles, etc per cell copy policy srcRow may be from a different sheet in the same workbook- Parameters:
- srcRow- the rows to copy from
- policy- the policy to determine what gets copied
 
 - 
copyRowFrom@Beta public void copyRowFrom(Row srcRow, CellCopyPolicy policy, CellCopyContext context) Copy the cells from srcRow to this row. If this row is not a blank row, this will merge the two rows, overwriting the cells in this row with the cells in srcRow. If srcRow is null, overwrite cells in destination row with blank values, styles, etc per cell copy policy. Note that if you are copying from a non-HSSF row then you will need to disable style copying in theCellCopyPolicy(HSSF styles are not compatible with XSSF styles, for instance).- Parameters:
- srcRow- the rows to copy from
- policy- the policy to determine what gets copied
- context- the context - see- CellCopyContext
- Since:
- v5.1.0
 
 - 
isCustomHeightpublic boolean isCustomHeight() 
 - 
setCustomHeightpublic void setCustomHeight(boolean b) 
 
- 
 
-