org.apache.poi.hssf.usermodel
Class HSSFCell

java.lang.Object
  |
  +--org.apache.poi.hssf.usermodel.HSSFCell

public class HSSFCell
extends java.lang.Object

High level representation of a cell in a row of a spreadsheet. Cells can be numeric, formula-based or string-based (text). The cell type specifies this. String cells cannot conatin numbers and numeric cells cannot contain strings (at least according to our model). Client apps should do the conversions themselves. Formula cells are treated like string cells, simply containing a formula string. They'll be rendered differently.

Cells should have their number (0 based) before being added to a row. Only cells that have values should be added.

NOTE: the alpha won't be implementing formulas

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

Field Summary
static int CELL_TYPE_BLANK
          Blank Cell type (3)
static int CELL_TYPE_BOOLEAN
          Boolean Cell type (4)
static int CELL_TYPE_ERROR
          Error Cell type (5)
static int CELL_TYPE_FORMULA
          Formula Cell type (2)
static int CELL_TYPE_NUMERIC
          Numeric Cell type (0)
static int CELL_TYPE_STRING
          String Cell type (1)
static short ENCODING_COMPRESSED_UNICODE
           
static short ENCODING_UTF_16
           
 
Constructor Summary
protected HSSFCell(Workbook book, Sheet sheet, short row, CellValueRecordInterface cval)
          Creates an HSSFCell from a CellValueRecordInterface.
protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
          Creates new Cell - Should only be called by HSSFRow.
protected HSSFCell(Workbook book, Sheet sheet, short row, short col, int type)
          Deprecated. As of 22-Jan-2002 use @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(short) and use setCellValue to specify the type lazily.
 
Method Summary
 boolean getBooleanCellValue()
          get the value of the cell as a boolean.
 short getCellNum()
          get the cell's number within the row
 HSSFCellStyle getCellStyle()
          get the style for the cell.
 int getCellType()
          get the cells type (numeric, formula or string)
protected  CellValueRecordInterface getCellValueRecord()
          Should only be used by HSSFSheet and friends.
 java.util.Date getDateCellValue()
          get the value of the cell as a date.
 short getEncoding()
          used for internationalization, currently 0 for compressed unicode or 1 for 16-bit
 byte getErrorCellValue()
          get the value of the cell as an error code.
 double getNumericCellValue()
          get the value of the cell as a number.
 java.lang.String getStringCellValue()
          get the value of the cell as a string - for numeric cells we throw an exception.
 void setCellErrorValue(byte value)
          set a error value for the cell
 void setCellNum(short num)
          set the cell's number within the row (0 based)
 void setCellStyle(HSSFCellStyle style)
          set the style for the cell.
 void setCellType(int cellType)
          set the cells type (numeric, formula or string) -- DONT USE FORMULAS IN THIS RELEASE WE'LL THROW YOU A RUNTIME EXCEPTION IF YOU DO
 void setCellValue(boolean value)
          set a boolean value for the cell
 void setCellValue(java.util.Calendar value)
          set a date value for the cell.
 void setCellValue(java.util.Date value)
          set a date value for the cell.
 void setCellValue(double value)
          set a numeric value for the cell
 void setCellValue(java.lang.String value)
          set a string value for the cell.
 void setEncoding(short encoding)
          set the encoding to either 8 or 16 bit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CELL_TYPE_NUMERIC

public static final int CELL_TYPE_NUMERIC
Numeric Cell type (0)
See Also:
setCellType(int), getCellType()

CELL_TYPE_STRING

public static final int CELL_TYPE_STRING
String Cell type (1)
See Also:
setCellType(int), getCellType()

CELL_TYPE_FORMULA

public static final int CELL_TYPE_FORMULA
Formula Cell type (2)
See Also:
setCellType(int), getCellType()

CELL_TYPE_BLANK

public static final int CELL_TYPE_BLANK
Blank Cell type (3)
See Also:
setCellType(int), getCellType()

CELL_TYPE_BOOLEAN

public static final int CELL_TYPE_BOOLEAN
Boolean Cell type (4)
See Also:
setCellType(int), getCellType()

CELL_TYPE_ERROR

public static final int CELL_TYPE_ERROR
Error Cell type (5)
See Also:
setCellType(int), getCellType()

ENCODING_COMPRESSED_UNICODE

public static final short ENCODING_COMPRESSED_UNICODE

ENCODING_UTF_16

public static final short ENCODING_UTF_16
Constructor Detail

HSSFCell

protected HSSFCell(Workbook book,
                   Sheet sheet,
                   short row,
                   short col)
Creates new Cell - Should only be called by HSSFRow. This creates a cell from scratch.

When the cell is initially created it is set to CELL_TYPE_BLANK. Cell types can be changed/overwritten by calling setCellValue with the appropriate type as a parameter although conversions from one type to another may be prohibited.

Parameters:
book - - Workbook record of the workbook containing this cell
sheet - - Sheet record of the sheet containing this cell
row - - the row of this cell
col - - the column for this cell
See Also:
HSSFRow.createCell(short)

HSSFCell

protected HSSFCell(Workbook book,
                   Sheet sheet,
                   short row,
                   short col,
                   int type)
Deprecated. As of 22-Jan-2002 use @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(short) and use setCellValue to specify the type lazily.

Creates new Cell - Should only be called by HSSFRow. This creates a cell from scratch.
Parameters:
book - - Workbook record of the workbook containing this cell
sheet - - Sheet record of the sheet containing this cell
row - - the row of this cell
col - - the column for this cell
type - - CELL_TYPE_NUMERIC, CELL_TYPE_STRING, CELL_TYPE_FORMULA, CELL_TYPE_BLANK, CELL_TYPE_BOOLEAN, CELL_TYPE_ERROR Type of cell
See Also:
HSSFRow.createCell(short,int)

HSSFCell

protected HSSFCell(Workbook book,
                   Sheet sheet,
                   short row,
                   CellValueRecordInterface cval)
Creates an HSSFCell from a CellValueRecordInterface. HSSFSheet uses this when reading in cells from an existing sheet.
Parameters:
book - - Workbook record of the workbook containing this cell
sheet - - Sheet record of the sheet containing this cell
cval - - the Cell Value Record we wish to represent
Method Detail

setCellNum

public void setCellNum(short num)
set the cell's number within the row (0 based)
Parameters:
num - short the cell number

getCellNum

public short getCellNum()
get the cell's number within the row
Returns:
short reperesenting the column number (logical!)

setCellType

public void setCellType(int cellType)
set the cells type (numeric, formula or string) -- DONT USE FORMULAS IN THIS RELEASE WE'LL THROW YOU A RUNTIME EXCEPTION IF YOU DO
See Also:
CELL_TYPE_NUMERIC, CELL_TYPE_STRING, CELL_TYPE_FORMULA, CELL_TYPE_BLANK, CELL_TYPE_BOOLEAN, CELL_TYPE_ERROR

getCellType

public int getCellType()
get the cells type (numeric, formula or string)
See Also:
CELL_TYPE_STRING, CELL_TYPE_NUMERIC, CELL_TYPE_FORMULA, CELL_TYPE_BOOLEAN, CELL_TYPE_ERROR

setCellValue

public void setCellValue(double value)
set a numeric value for the cell
Parameters:
value - the numeric value to set this cell to. For formulas we'll set the precalculated value, for numerics we'll set its value. For other types we will change the cell to a numeric cell and set its value.

setCellValue

public void setCellValue(java.util.Date value)
set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as a date.
Parameters:
value - the date value to set this cell to. For formulas we'll set the precalculated value, for numerics we'll set its value. For other types we will change the cell to a numeric cell and set its value.

setCellValue

public void setCellValue(java.util.Calendar value)
set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as a date.
Parameters:
value - the date value to set this cell to. For formulas we'll set the precalculated value, for numerics we'll set its value. For othertypes we will change the cell to a numeric cell and set its value.

setCellValue

public void setCellValue(java.lang.String value)
set a string value for the cell.
Parameters:
value - value to set the cell to. For formulas we'll set the formula string, for String cells we'll set its value. For other types we will change the cell to a string cell and set its value. If value is null then we will change the cell to a Blank cell.

getNumericCellValue

public double getNumericCellValue()
get the value of the cell as a number. For strings we throw an exception. For blank cells we return a 0.

getDateCellValue

public java.util.Date getDateCellValue()
get the value of the cell as a date. For strings we throw an exception. For blank cells we return a null.

getStringCellValue

public java.lang.String getStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception. For blank cells we return an empty string.

setCellValue

public void setCellValue(boolean value)
set a boolean value for the cell
Parameters:
value - the boolean value to set this cell to. For formulas we'll set the precalculated value, for booleans we'll set its value. For other types we will change the cell to a boolean cell and set its value.

setCellErrorValue

public void setCellErrorValue(byte value)
set a error value for the cell
Parameters:
value - the error value to set this cell to. For formulas we'll set the precalculated value ??? IS THIS RIGHT??? , for errors we'll set its value. For other types we will change the cell to an error cell and set its value.

getBooleanCellValue

public boolean getBooleanCellValue()
get the value of the cell as a boolean. For strings, numbers, and errors, we throw an exception. For blank cells we return a false.

getErrorCellValue

public byte getErrorCellValue()
get the value of the cell as an error code. For strings, numbers, and booleans, we throw an exception. For blank cells we return a 0.

setCellStyle

public void setCellStyle(HSSFCellStyle style)
set the style for the cell. The style should be an HSSFCellStyle created/retreived from the HSSFWorkbook.
Parameters:
style - reference contained in the workbook
See Also:
HSSFWorkbook.createCellStyle(), HSSFWorkbook.getCellStyleAt(short)

getCellStyle

public HSSFCellStyle getCellStyle()
get the style for the cell. This is a reference to a cell style contained in the workbook object.
See Also:
HSSFWorkbook.getCellStyleAt(short)

getEncoding

public short getEncoding()
used for internationalization, currently 0 for compressed unicode or 1 for 16-bit
Returns:
1 or 0 for compressed or uncompressed (used only with String type)
See Also:
ENCODING_COMPRESSED_UNICODE, ENCODING_UTF_16

setEncoding

public void setEncoding(short encoding)
set the encoding to either 8 or 16 bit. (US/UK use 8-bit, rest of the western world use 16bit)
Parameters:
encoding - either ENCODING_COMPRESSED_UNICODE (0) or ENCODING_UTF_16 (1)
See Also:
ENCODING_COMPRESSED_UNICODE, ENCODING_UTF_16

getCellValueRecord

protected CellValueRecordInterface getCellValueRecord()
Should only be used by HSSFSheet and friends. Returns the low level CellValueRecordInterface record
Returns:
CellValueRecordInterface representing the cell via the low level api.


Copyright © 2002 Apache jakarta-poi project. All Rights Reserved.