org.apache.poi.hssf.usermodel
Class HSSFRow

java.lang.Object
  extended by org.apache.poi.hssf.usermodel.HSSFRow
All Implemented Interfaces:
java.lang.Comparable, java.lang.Iterable<org.apache.poi.ss.usermodel.Cell>, org.apache.poi.ss.usermodel.Row

public final class HSSFRow
extends java.lang.Object
implements java.lang.Comparable, org.apache.poi.ss.usermodel.Row

High level representation of a row of a spreadsheet. Only rows that have cells should be added to a Sheet.

Version:
1.0-pre
Author:
Andrew C. Oliver (acoliver at apache dot org), Glen Stampoultzis (glens at apache.org)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.poi.ss.usermodel.Row
org.apache.poi.ss.usermodel.Row.MissingCellPolicy
 
Field Summary
static int INITIAL_CAPACITY
           
 
Fields inherited from interface org.apache.poi.ss.usermodel.Row
CREATE_NULL_AS_BLANK, RETURN_BLANK_AS_NULL, RETURN_NULL_AND_BLANK
 
Method Summary
 java.util.Iterator cellIterator()
           
 int compareTo(java.lang.Object obj)
           
 HSSFCell createCell(int column)
          Use this to create new cells within the row and return it.
 HSSFCell createCell(short column)
          Use this to create new cells within the row and return it.
 HSSFCell createCell(short column, int type)
          Use this to create new cells within the row and return it.
protected  HSSFCell createCellFromRecord(CellValueRecordInterface cell)
          create a high level HSSFCell object from an existing low level record.
 boolean equals(java.lang.Object obj)
           
 HSSFCell getCell(int cellnum)
          Get the hssfcell representing a given column (logical cell) 0-based.
 HSSFCell getCell(int cellnum, org.apache.poi.ss.usermodel.Row.MissingCellPolicy policy)
          Get the hssfcell representing a given column (logical cell) 0-based.
 HSSFCell getCell(short cellnum)
          Get the hssfcell representing a given column (logical cell) 0-based.
 short getFirstCellNum()
          get the number of the first cell contained in this row.
 short getHeight()
          get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)
 float getHeightInPoints()
          get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())
 short getLastCellNum()
          Gets the index of the last cell contained in this row PLUS ONE.
protected  int getOutlineLevel()
          Returns the rows outline level.
 int getPhysicalNumberOfCells()
          gets the number of defined cells (NOT number of cells in the actual row!).
 int getRowNum()
          get row number this row represents
protected  RowRecord getRowRecord()
          get the lowlevel RowRecord represented by this object - should only be called by other parts of the high level API
 boolean getZeroHeight()
          get whether or not to display this row with 0 height
 java.util.Iterator iterator()
          Alias for CellIterator to allow foreach loops
 void moveCell(HSSFCell cell, short newColumn)
          Moves the supplied cell to a new column, which must not already have a cell there!
protected  void removeAllCells()
          Removes all the cells from the row, and their records too.
 void removeCell(org.apache.poi.ss.usermodel.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 rowNum)
          set the row number of this row.
 void setZeroHeight(boolean zHeight)
          set whether or not to display this row with 0 height
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

public static final int INITIAL_CAPACITY
See Also:
Constant Field Values
Method Detail

createCell

public HSSFCell createCell(short column)
Use this to create new cells within the row and return it.

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

Specified by:
createCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
column - - the column number this cell represents
Returns:
HSSFCell a high level representation of the created cell.

createCell

public HSSFCell createCell(int column)
Use this to create new cells within the row and return it.

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

Specified by:
createCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
column - - the column number this cell represents
Returns:
HSSFCell a high level representation of the created cell.

createCell

public HSSFCell createCell(short column,
                           int type)
Use this to create new cells within the row and return it.

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

Specified by:
createCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
column - - the column number this cell represents
Returns:
HSSFCell a high level representation of the created cell.

removeCell

public void removeCell(org.apache.poi.ss.usermodel.Cell cell)
remove the HSSFCell from this row.

Specified by:
removeCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
cell - to remove

removeAllCells

protected void removeAllCells()
Removes all the cells from the row, and their records too.


createCellFromRecord

protected HSSFCell createCellFromRecord(CellValueRecordInterface cell)
create a high level HSSFCell object from an existing low level record. Should only be called from HSSFSheet or HSSFRow itself.

Parameters:
cell - low level cell to create the high level representation from
Returns:
HSSFCell representing the low level record passed in

setRowNum

public void setRowNum(int rowNum)
set the row number of this row.

Specified by:
setRowNum in interface org.apache.poi.ss.usermodel.Row
Parameters:
rowNum - the row number (0-based)
Throws:
java.lang.IndexOutOfBoundsException - if the row number is not within the range 0-65535.

getRowNum

public int getRowNum()
get row number this row represents

Specified by:
getRowNum in interface org.apache.poi.ss.usermodel.Row
Returns:
the row number (0 based)

getOutlineLevel

protected int getOutlineLevel()
Returns the rows outline level. Increased as you put it into more groups (outlines), reduced as you take it out of them. TODO - Should this really be public?


moveCell

public 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)

getCell

public HSSFCell getCell(short 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 different MissingCellPolicy on the base workbook. Short method signature provided to retain binary compatibility.

Parameters:
cellnum - 0 based column number
Returns:
HSSFCell representing that column or null if undefined.

getCell

public 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 different MissingCellPolicy on the base workbook.

Specified by:
getCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
cellnum - 0 based column number
Returns:
HSSFCell representing that column or null if undefined.

getCell

public HSSFCell getCell(int cellnum,
                        org.apache.poi.ss.usermodel.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

Specified by:
getCell in interface org.apache.poi.ss.usermodel.Row
Parameters:
cellnum - 0 based column number
policy - Policy on blank / missing cells
Returns:
representing that column or null if undefined + policy allows.

getFirstCellNum

public short getFirstCellNum()
get the number of the first cell contained in this row.

Specified by:
getFirstCellNum in interface org.apache.poi.ss.usermodel.Row
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 interface org.apache.poi.ss.usermodel.Row
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 interface org.apache.poi.ss.usermodel.Row
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.

Specified by:
setHeight in interface org.apache.poi.ss.usermodel.Row
Parameters:
height - rowheight or 0xff for undefined (use sheet default)

setZeroHeight

public void setZeroHeight(boolean zHeight)
set whether or not to display this row with 0 height

Specified by:
setZeroHeight in interface org.apache.poi.ss.usermodel.Row
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 interface org.apache.poi.ss.usermodel.Row
Returns:
- zHeight height is zero or not.

setHeightInPoints

public void setHeightInPoints(float height)
set the row's height in points.

Specified by:
setHeightInPoints in interface org.apache.poi.ss.usermodel.Row
Parameters:
height - row height in points

getHeight

public short getHeight()
get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)

Specified by:
getHeight in interface org.apache.poi.ss.usermodel.Row
Returns:
rowheight or 0xff for undefined (use sheet default)

getHeightInPoints

public float getHeightInPoints()
get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())

Specified by:
getHeightInPoints in interface org.apache.poi.ss.usermodel.Row
Returns:
rowheight or 0xff for undefined (use sheet default)

getRowRecord

protected 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

cellIterator

public java.util.Iterator cellIterator()
Specified by:
cellIterator in interface org.apache.poi.ss.usermodel.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.

iterator

public java.util.Iterator iterator()
Alias for CellIterator to allow foreach loops

Specified by:
iterator in interface java.lang.Iterable<org.apache.poi.ss.usermodel.Cell>
Specified by:
iterator in interface org.apache.poi.ss.usermodel.Row

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
Specified by:
compareTo in interface org.apache.poi.ss.usermodel.Row

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface org.apache.poi.ss.usermodel.Row
Overrides:
equals in class java.lang.Object


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.