FileDocCategorySizeDatePackage
HSSFRow.javaAPI DocApache Poi 3.0.113871Mon Jan 01 12:39:36 GMT 2007org.apache.poi.hssf.usermodel

HSSFRow

public class HSSFRow extends Object implements Comparable
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)
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
public static final int
INITIAL_CAPACITY
private int
rowNum
private HSSFCell[]
cells
private RowRecord
row
reference to low level representation
private org.apache.poi.hssf.model.Workbook
book
reference to containing low level Workbook
private org.apache.poi.hssf.model.Sheet
sheet
reference to containing Sheet
Constructors Summary
protected HSSFRow()


     
    
    
protected HSSFRow(org.apache.poi.hssf.model.Workbook book, org.apache.poi.hssf.model.Sheet sheet, int rowNum)
Creates new HSSFRow from scratch. Only HSSFSheet should do this.

param
book low-level Workbook object containing the sheet that contains this row
param
sheet low-level Sheet object that contains this Row
param
rowNum the row number of this row (0 based)
see
org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)

        this.rowNum = rowNum;
        this.book = book;
        this.sheet = sheet;
        row = new RowRecord();
        row.setOptionFlags( (short)0x100 );   // seems necessary for outlining to work.  
        row.setHeight((short) 0xff);
        row.setLastCol((short) -1);
        row.setFirstCol((short) -1);

        setRowNum(rowNum);
    
protected HSSFRow(org.apache.poi.hssf.model.Workbook book, org.apache.poi.hssf.model.Sheet sheet, RowRecord record)
Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do this. HSSFSheet uses this when an existing file is read in.

param
book low-level Workbook object containing the sheet that contains this row
param
sheet low-level Sheet object that contains this Row
param
record the low level api object this row should represent
see
org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)

        this.book = book;
        this.sheet = sheet;
        row = record;

        setRowNum(record.getRowNumber());
    
Methods Summary
private voidaddCell(org.apache.poi.hssf.usermodel.HSSFCell cell)
used internally to add a cell.

        short column=cell.getCellNum();
        if (row.getFirstCol() == -1)
        {
            row.setFirstCol(column);
        }
        if (row.getLastCol() == -1)
        {
            row.setLastCol(column);
        }

        if(column>=cells.length)
        {
          HSSFCell[] oldCells=cells;
          int newSize=oldCells.length*2;
          if(newSize<column+1) newSize=column+1;
          cells=new HSSFCell[newSize];
          System.arraycopy(oldCells,0,cells,0,oldCells.length);
        }
        cells[column]=cell;

        if (column < row.getFirstCol())
        {
            row.setFirstCol(column);
        }
        if (column > row.getLastCol())
        {
            row.setLastCol(column);
        }
    
public java.util.IteratorcellIterator()

return
cell iterator of the physically defined cells. Note element 4 may actually be row cell depending on how many are defined!

      return new CellIterator();
    
public intcompareTo(java.lang.Object obj)

        HSSFRow loc = (HSSFRow) obj;

        if (this.getRowNum() == loc.getRowNum())
        {
            return 0;
        }
        if (this.getRowNum() < loc.getRowNum())
        {
            return -1;
        }
        if (this.getRowNum() > loc.getRowNum())
        {
            return 1;
        }
        return -1;
    
public org.apache.poi.hssf.usermodel.HSSFCellcreateCell(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.

param
column - the column number this cell represents
return
HSSFCell a high level representation of the created cell.

      return this.createCell(column,HSSFCell.CELL_TYPE_BLANK);
    
public org.apache.poi.hssf.usermodel.HSSFCellcreateCell(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.

param
column - the column number this cell represents
return
HSSFCell a high level representation of the created cell.

        HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column, type);

        addCell(cell);
        sheet.addValueRecord(getRowNum(), cell.getCellValueRecord());
        return cell;
    
protected org.apache.poi.hssf.usermodel.HSSFCellcreateCellFromRecord(org.apache.poi.hssf.record.CellValueRecordInterface cell)
create a high level HSSFCell object from an existing low level record. Should only be called from HSSFSheet or HSSFRow itself.

param
cell low level cell to create the high level representation from
return
HSSFCell representing the low level record passed in

        HSSFCell hcell = new HSSFCell(book, sheet, getRowNum(), cell);

        addCell(hcell);

        // sheet.addValueRecord(getRowNum(),cell.getCellValueRecord());
        return hcell;
    
public booleanequals(java.lang.Object obj)

        if (!(obj instanceof HSSFRow))
        {
            return false;
        }
        HSSFRow loc = (HSSFRow) obj;

        if (this.getRowNum() == loc.getRowNum())
        {
            return true;
        }
        return false;
    
private shortfindFirstCell(short firstcell)
used internally to refresh the "first cell" when the first cell is removed.

        short cellnum = (short) (firstcell + 1);
        HSSFCell r = getCell(cellnum);

        while (r == null && cellnum <= getLastCellNum())
        {
            r = getCell(++cellnum);
        }
        if (cellnum > getLastCellNum())
            return -1;
        return cellnum;
    
private shortfindLastCell(short lastcell)
used internally to refresh the "last cell" when the last cell is removed.

        short cellnum = (short) (lastcell - 1);
        HSSFCell r = getCell(cellnum);

        while (r == null && cellnum >= 0)
        {
            r = getCell(--cellnum);
        }
        return cellnum;
    
public org.apache.poi.hssf.usermodel.HSSFCellgetCell(short cellnum)
get the hssfcell representing a given column (logical cell) 0-based. If you ask for a cell that is not defined....you get a null.

param
cellnum 0 based column number
return
HSSFCell representing that column or null if undefined.

      if(cellnum<0||cellnum>=cells.length) return null;
      return cells[cellnum];
    
public shortgetFirstCellNum()
get the number of the first cell contained in this row.

return
short representing the first logical cell in the row, or -1 if the row does not contain any cells.

        if (getPhysicalNumberOfCells() == 0)
            return -1;
        else
            return row.getFirstCol();
    
public shortgetHeight()
get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)

return
rowheight or 0xff for undefined (use sheet default)

        return row.getHeight();
    
public floatgetHeightInPoints()
get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())

return
rowheight or 0xff for undefined (use sheet default)

        return (row.getHeight() / 20);
    
public shortgetLastCellNum()
gets the number of the last cell contained in this row PLUS ONE.

return
short representing the last logical cell in the row PLUS ONE, or -1 if the row does not contain any cells.

        if (getPhysicalNumberOfCells() == 0)
            return -1;
        else
            return row.getLastCol();
    
public intgetPhysicalNumberOfCells()
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.

return
int representing the number of defined cells in the row.

      int count=0;
      for(int i=0;i<cells.length;i++)
      {
        if(cells[i]!=null) count++;
      }
      return count;
    
public intgetRowNum()
get row number this row represents

return
the row number (0 based)

        return rowNum;
    
protected org.apache.poi.hssf.record.RowRecordgetRowRecord()
get the lowlevel RowRecord represented by this object - should only be called by other parts of the high level API

return
RowRecord this row represents

        return row;
    
public booleangetZeroHeight()
get whether or not to display this row with 0 height

return
- zHeight height is zero or not.

        return row.getZeroHeight();
    
public voidremoveCell(org.apache.poi.hssf.usermodel.HSSFCell cell)
remove the HSSFCell from this row.

param
cell to remove

        CellValueRecordInterface cval = cell.getCellValueRecord();

        sheet.removeValueRecord(getRowNum(), cval);
        short column=cell.getCellNum();
        if(cell!=null && column<cells.length)
        {
          cells[column]=null;
        }

        if (cell.getCellNum() == row.getLastCol())
        {
            row.setLastCol(findLastCell(row.getLastCol()));
        }
        if (cell.getCellNum() == row.getFirstCol())
        {
            row.setFirstCol(findFirstCell(row.getFirstCol()));
        }
    
public voidsetHeight(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.

param
height rowheight or 0xff for undefined (use sheet default)


        // row.setOptionFlags(
        row.setBadFontHeight(true);
        row.setHeight(height);
    
public voidsetHeightInPoints(float height)
set the row's height in points.

param
height row height in points


        // row.setOptionFlags(
        row.setBadFontHeight(true);
        row.setHeight((short) (height * 20));
    
public voidsetRowNum(int rowNum)
set the row number of this row.

param
rowNum the row number (0-based)
throws
IndexOutOfBoundsException if the row number is not within the range 0-65535.

        if ((rowNum < 0) || (rowNum > RowRecord.MAX_ROW_NUMBER))
          throw new IndexOutOfBoundsException("Row number must be between 0 and "+RowRecord.MAX_ROW_NUMBER+", was <"+rowNum+">");
        this.rowNum = rowNum;
        if (row != null)
        {
            row.setRowNumber(rowNum);   // used only for KEY comparison (HSSFRow)
        }
    
public voidsetZeroHeight(boolean zHeight)
set whether or not to display this row with 0 height

param
zHeight height is zero or not.

        row.setZeroHeight(zHeight);