Package org.apache.poi.ss.usermodel
Interface Row
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classRow.MissingCellPolicyUsed to specify the different possible policies if for the case of null and blank cells
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Iterator<Cell>cellIterator()CellcreateCell(int column)Use this to create new cells within the row and return it.CellcreateCell(int column, CellType type)Use this to create new cells within the row and return it.CellgetCell(int cellnum)Get the cell representing a given column (logical cell) 0-based.CellgetCell(int cellnum, Row.MissingCellPolicy policy)Returns the cell at the given (0 based) index, with the specifiedRow.MissingCellPolicyshortgetFirstCellNum()Get the number of the first cell contained in this row.shortgetHeight()Get the row's height measured in twips (1/20th of a point).floatgetHeightInPoints()Returns row height measured in point size.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 representsCellStylegetRowStyle()Returns the whole-row cell styles.SheetgetSheet()Returns the Sheet this row belongs tobooleangetZeroHeight()Get whether or not to display this row with 0 heightbooleanisFormatted()Is this row formatted? Most aren't, but some rows do have whole-row styles.default Iterator<Cell>iterator()Alias forcellIterator()to allow foreach loops:voidremoveCell(Cell cell)Remove the Cell from this row.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 rowNum)Set the row number of this 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)voidshiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)default Spliterator<Cell>spliterator()
-
-
-
Method Detail
-
createCell
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 callingsetCellValueorsetCellType.- Parameters:
column- - the column number this cell represents- Returns:
- Cell a high level representation of the created cell.
- Throws:
IllegalArgumentException- if columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
-
createCell
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- - the column number this cell representstype- - the cell's data type- Returns:
- Cell a high level representation of the created cell.
- Throws:
IllegalArgumentException- if columnIndex < 0 or greater than a maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
-
removeCell
void removeCell(Cell cell)
Remove the Cell from this row.- Parameters:
cell- the cell to remove
-
setRowNum
void setRowNum(int rowNum)
Set the row number of this row.- Parameters:
rowNum- the row number (0-based)- Throws:
IllegalArgumentException- if rowNum < 0
-
getRowNum
int getRowNum()
Get row number this row represents- Returns:
- the row number (0 based)
-
getCell
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- 0 based column number- Returns:
- Cell representing that column or null if undefined.
- See Also:
getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
-
getCell
Cell getCell(int cellnum, Row.MissingCellPolicy policy)
Returns the cell at the given (0 based) index, with the specifiedRow.MissingCellPolicy- Returns:
- the cell at the given (0 based) index
- Throws:
IllegalArgumentException- if cellnum < 0 or the specified MissingCellPolicy is invalid
-
getFirstCellNum
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 representing the first logical cell in the row, or -1 if the row does not contain any cells.
-
getLastCellNum
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 representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.
-
getPhysicalNumberOfCells
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 representing the number of defined cells in the row.
-
setHeight
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- rowheight or 0xff for undefined (use sheet default)
-
setZeroHeight
void setZeroHeight(boolean zHeight)
Set whether or not to display this row with 0 height- Parameters:
zHeight- height is zero or not.
-
getZeroHeight
boolean getZeroHeight()
Get whether or not to display this row with 0 height- Returns:
- - zHeight height is zero or not.
-
setHeightInPoints
void setHeightInPoints(float height)
Set the row's height in points.- Parameters:
height- the height in points.-1resets to the default height
-
getHeight
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, SeeSheet.getDefaultRowHeightInPoints()- Returns:
- row height measured in twips (1/20th of a point)
-
getHeightInPoints
float getHeightInPoints()
Returns row height measured in point size. If the height is not set, the default worksheet value is returned, SeeSheet.getDefaultRowHeightInPoints()- Returns:
- row height measured in point size
- See Also:
Sheet.getDefaultRowHeightInPoints()
-
isFormatted
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()
-
getRowStyle
CellStyle getRowStyle()
Returns the whole-row cell styles. Most rows won't have one of these, so will return null. CallisFormatted()to check first.
-
setRowStyle
void setRowStyle(CellStyle style)
Applies a whole-row cell styling to the row.
-
cellIterator
Iterator<Cell> cellIterator()
- Returns:
- Cell iterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!
-
iterator
default Iterator<Cell> iterator()
Alias forcellIterator()to allow foreach loops:for(Cell cell : row){ ... }
-
spliterator
default Spliterator<Cell> spliterator()
- Specified by:
spliteratorin interfaceIterable<Cell>- Returns:
- Cell spliterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!
- Since:
- POI 5.2.0
-
getSheet
Sheet getSheet()
Returns the Sheet this row belongs to- Returns:
- the Sheet that owns this row
-
getOutlineLevel
int getOutlineLevel()
Returns the rows outline level. Increased as you put it into more groups (outlines), reduced as you take it out of them.
-
shiftCellsRight
void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
-
shiftCellsLeft
void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
-
-