Package org.apache.poi.xssf.usermodel
Class XSSFRow
java.lang.Object
org.apache.poi.xssf.usermodel.XSSFRow
- All Implemented Interfaces:
Comparable<XSSFRow>,Iterable<Cell>,Row
High level representation of a row of a spreadsheet.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.poi.ss.usermodel.Row
Row.MissingCellPolicy -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCell iterator over the physically defined cells:intCompares twoXSSFRowobjects.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 workbookcreateCell(int columnIndex) 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.booleangetCell(int cellnum) Returns the cell at the given (0 based) index, with theRow.MissingCellPolicyfrom the parent Workbook.getCell(int cellnum, Row.MissingCellPolicy policy) Returns the cell at the given (0 based) index, with the specifiedRow.MissingCellPolicyorg.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowgetCTRow()Returns the underlying CTRow xml bean containing all cell definitions in this rowshortGet the 0-based number of the first cell contained in this row.shortGet the row's height measured in twips (1/20th of a point).floatReturns row height measured in point size.shortGets the index of the last cell contained in this row PLUS ONE.intReturns the rows outline level.intGets the number of defined cells (NOT number of cells in the actual row!).intGet row number this row representsReturns the whole-row cell style.getSheet()Returns the XSSFSheet this row belongs tobooleanGet whether or not to display this row with 0 heightinthashCode()booleanIs this row formatted? Most aren't, but some rows do have whole-row styles.iterator()Alias forcellIterator()to allow foreach loops:protected voidFired when the document is written to an output stream.voidremoveCell(Cell cell) Remove the Cell from this row.voidsetHeight(short height) Set the height in "twips" or 1/20th of a point.voidsetHeightInPoints(float height) Set the row's height in points.voidsetRowNum(int rowIndex) Set the row number of this row.voidsetRowStyle(CellStyle style) Applies a whole-row cell styling to the row.voidsetZeroHeight(boolean height) Set whether or not to display this row with 0 heightprotected voidshift(int n) update cell references when shifting rowsvoidshiftCellsLeft(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.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
XSSFRow
Construct a XSSFRow.- Parameters:
row- the xml bean containing all cell definitions for this row.sheet- the parent sheet.
-
-
Method Details
-
getSheet
Returns the XSSFSheet this row belongs to -
cellIterator
Cell iterator over the physically defined cells:for (Iterator
it = row.cellIterator(); it.hasNext(); ) { Cell cell = it.next(); ... } | - Specified by:
cellIteratorin interfaceRow- Returns:
- an iterator over cells in this row.
-
iterator
Alias forcellIterator()to allow foreach loops:for(Cell cell : row){ ... } -
compareTo
Compares twoXSSFRowobjects. Two rows are equal if they belong to the same worksheet and their row indexes are equal.- Specified by:
compareToin interfaceComparable<XSSFRow>- Parameters:
other- theXSSFRowto be compared.- Returns:
-
the value
0if the row number of thisXSSFRowis equal to the row number of the argumentXSSFRow -
a value less than
0if the row number of this thisXSSFRowis numerically less than the row number of the argumentXSSFRow -
a value greater than
0if the row number of this thisXSSFRowis numerically greater than the row number of the argumentXSSFRow
-
the value
- Throws:
IllegalArgumentException- if the argument row belongs to a different worksheet
-
equals
-
hashCode
public int hashCode() -
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 callingsetCellValueorsetCellType.- Specified by:
createCellin interfaceRow- Parameters:
columnIndex- - the column number this cell represents- Returns:
- Cell a high level representation of the created cell.
- Throws:
IllegalArgumentException- if columnIndex < 0 or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx)
-
createCell
Use this to create new cells within the row and return it.- Specified by:
createCellin interfaceRow- Parameters:
columnIndex- - the column number this cell representstype- - the cell's data type- Returns:
- XSSFCell a high level representation of the created cell.
- Throws:
IllegalArgumentException- if the specified cell type is invalid, columnIndex < 0 or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx)
-
getCell
Returns the cell at the given (0 based) index, with theRow.MissingCellPolicyfrom the parent Workbook. -
getCell
Returns the cell at the given (0 based) index, with the specifiedRow.MissingCellPolicy- Specified by:
getCellin interfaceRow- Returns:
- the cell at the given (0 based) index
- Throws:
IllegalArgumentException- if cellnum < 0 or the specified MissingCellPolicy is invalid
-
getFirstCellNum
public short getFirstCellNum()Get the 0-based number of the first cell contained in this row.- Specified by:
getFirstCellNumin 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++) { XSSFCell cell = row.getCell(colIx); if(cell == null) { continue; } //... do something with cell }- Specified by:
getLastCellNumin interfaceRow- Returns:
- short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.
-
getHeight
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, SeeXSSFSheet.getDefaultRowHeightInPoints() -
getHeightInPoints
public float getHeightInPoints()Returns row height measured in point size. If the height is not set, the default worksheet value is returned, SeeXSSFSheet.getDefaultRowHeightInPoints()- Specified by:
getHeightInPointsin interfaceRow- Returns:
- row height measured in point size
- See Also:
-
setHeight
public void setHeight(short height) Set the height in "twips" or 1/20th of a point. -
setHeightInPoints
public void setHeightInPoints(float height) Set the row's height in points.- Specified by:
setHeightInPointsin interfaceRow- Parameters:
height- the height in points.-1resets to the default height
-
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:
getPhysicalNumberOfCellsin interfaceRow- Returns:
- int representing the number of defined cells in the row.
-
getRowNum
public int getRowNum()Get row number this row represents -
setRowNum
public void setRowNum(int rowIndex) Set the row number of this row.- Specified by:
setRowNumin interfaceRow- Parameters:
rowIndex- the row number (0-based)- Throws:
IllegalArgumentException- if rowNum < 0 or greater than 1048575
-
getZeroHeight
public boolean getZeroHeight()Get whether or not to display this row with 0 height- Specified by:
getZeroHeightin interfaceRow- Returns:
- - height is zero or not.
-
setZeroHeight
public void setZeroHeight(boolean height) Set whether or not to display this row with 0 height- Specified by:
setZeroHeightin interfaceRow- Parameters:
height- height is zero or not.
-
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:
isFormattedin interfaceRow
-
getRowStyle
Returns the whole-row cell style. Most rows won't have one of these, so will return null. CallisFormatted()to check first.- Specified by:
getRowStylein interfaceRow
-
setRowStyle
Applies a whole-row cell styling to the row. If the value is null then the style information is removed, causing the cell to used the default workbook style.- Specified by:
setRowStylein interfaceRow
-
removeCell
Remove the Cell from this row.- Specified by:
removeCellin interfaceRow- Parameters:
cell- the cell to remove
-
getCTRow
Returns the underlying CTRow xml bean containing all cell definitions in this row- Returns:
- the underlying CTRow xml bean
-
onDocumentWrite
protected void onDocumentWrite()Fired when the document is written to an output stream.- See Also:
-
toString
-
shift
protected void shift(int n) update cell references when shifting rows- Parameters:
n- the number of rows to move
-
copyRowFrom
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 frompolicy- the policy to determine what gets copied
-
getOutlineLevel
public int getOutlineLevel()Description copied from interface:RowReturns the rows outline level. Increased as you put it into more groups (outlines), reduced as you take it out of them.- Specified by:
getOutlineLevelin interfaceRow
-
shiftCellsRight
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.- Specified by:
shiftCellsRightin 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:
shiftCellsLeftin interfaceRow- Parameters:
firstShiftColumnIndex- the column to start shiftinglastShiftColumnIndex- the column to end shiftingstep- length of the shifting step
-