Package loci.poi.hssf.usermodel
Class HSSFCell
java.lang.Object
loci.poi.hssf.usermodel.HSSFCell
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 have the formula string, as well as
the formula result, which can be numeric or string.
Cells should have their number (0 based) before being added to a row. Only cells that have values should be added.
- Version:
- 1.0-pre
- Author:
- Andrew C. Oliver (acoliver at apache dot org), Dan Sherman (dsherman at isisph.com), Brian Sanders (kestrel at burdell dot org) Active Cell support, Yegor Kozlov cell comments support
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBlank Cell type (3)static final intBoolean Cell type (4)static final intError Cell type (5)static final intFormula Cell type (2)static final intNumeric Cell type (0)static final intString Cell type (1)static final shortstatic final shortstatic final short -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates new Cell - Should only be called by HSSFRow.protectedCreates new Cell - Should only be called by HSSFRow.protectedHSSFCell(Workbook book, Sheet sheet, int row, CellValueRecordInterface cval) Creates an HSSFCell from a CellValueRecordInterface. -
Method Summary
Modifier and TypeMethodDescriptionprotected static HSSFCommentfindCellComment(Sheet sheet, int row, int column) Cell comment finder.booleanget the value of the cell as a boolean.protected WorkbookReturns the Workbook that this Cell is bound toReturns comment associated with this cellshortget the cell's number within the rowget the style for the cell.intget the cells type (numeric, formula or string)protected CellValueRecordInterfaceShould only be used by HSSFSheet and friends.get the value of the cell as a date.shortDeprecated.As of 3-Jan-06 POI now automatically handles Unicode without forcing the encoding.byteget the value of the cell as an error code.doubleget the value of the cell as a number.get the value of the cell as a string - for numeric cells we throw an exception.Deprecated.Use the HSSFRichTextString returnvoidSets this cell as the active cell for the worksheetvoidsetCellComment(HSSFComment comment) Assign a comment to this cellvoidsetCellErrorValue(byte value) set a error value for the cellvoidsetCellFormula(String formula) voidsetCellNum(short num) set the cell's number within the row (0 based)voidsetCellStyle(HSSFCellStyle style) set the style for the cell.voidsetCellType(int cellType) set the cells type (numeric, formula or string)voidsetCellValue(boolean value) set a boolean value for the cellvoidsetCellValue(double value) set a numeric value for the cellvoidsetCellValue(String value) Deprecated.Use setCellValue(HSSFRichTextString) instead.voidsetCellValue(Calendar value) set a date value for the cell.voidsetCellValue(Date value) set a date value for the cell.voidsetCellValue(HSSFRichTextString value) set a string value for the cell.voidsetEncoding(short encoding) Deprecated.As of 3-Jan-06 POI now automatically handles Unicode without forcing the encoding.toString()Returns a string representation of the cell This method returns a simple representation, anthing more complex should be in user code, with knowledge of the semantics of the sheet being processed.
-
Field Details
-
CELL_TYPE_NUMERIC
public static final int CELL_TYPE_NUMERICNumeric Cell type (0) -
CELL_TYPE_STRING
public static final int CELL_TYPE_STRINGString Cell type (1) -
CELL_TYPE_FORMULA
public static final int CELL_TYPE_FORMULAFormula Cell type (2) -
CELL_TYPE_BLANK
public static final int CELL_TYPE_BLANKBlank Cell type (3) -
CELL_TYPE_BOOLEAN
public static final int CELL_TYPE_BOOLEANBoolean Cell type (4) -
CELL_TYPE_ERROR
public static final int CELL_TYPE_ERRORError Cell type (5) -
ENCODING_UNCHANGED
public static final short ENCODING_UNCHANGED- See Also:
-
ENCODING_COMPRESSED_UNICODE
public static final short ENCODING_COMPRESSED_UNICODE- See Also:
-
ENCODING_UTF_16
public static final short ENCODING_UTF_16- See Also:
-
-
Constructor Details
-
HSSFCell
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 cellsheet- - Sheet record of the sheet containing this cellrow- - the row of this cellcol- - the column for this cell- See Also:
-
HSSFCell
Creates new Cell - Should only be called by HSSFRow. This creates a cell from scratch.- Parameters:
book- - Workbook record of the workbook containing this cellsheet- - Sheet record of the sheet containing this cellrow- - the row of this cellcol- - the column for this celltype- - CELL_TYPE_NUMERIC, CELL_TYPE_STRING, CELL_TYPE_FORMULA, CELL_TYPE_BLANK, CELL_TYPE_BOOLEAN, CELL_TYPE_ERROR Type of cell- See Also:
-
HSSFCell
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 cellsheet- - Sheet record of the sheet containing this cellcval- - the Cell Value Record we wish to represent
-
-
Method Details
-
getBoundWorkbook
Returns the Workbook that this Cell is bound to- Returns:
- the workbook the cell is bound to
-
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) -
getCellType
public int getCellType()get the cells type (numeric, formula or string) -
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
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
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
Deprecated.Use setCellValue(HSSFRichTextString) instead.set a string value for the cell. Please note that if you are using full 16 bit unicode you should callsetEncoding()first.- 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.
-
setCellValue
set a string value for the cell. Please note that if you are using full 16 bit unicode you should callsetEncoding()first.- 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.
-
setCellFormula
-
getCellFormula
-
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
get the value of the cell as a date. For strings we throw an exception. For blank cells we return a null. -
getStringCellValue
Deprecated.Use the HSSFRichTextString returnget the value of the cell as a string - for numeric cells we throw an exception. For blank cells we return an empty string. For formulaCells that are not string Formulas, we return empty String -
getRichStringCellValue
get the value of the cell as a string - for numeric cells we throw an exception. For blank cells we return an empty string. For formulaCells that are not string Formulas, we return 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
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:
-
getCellStyle
get the style for the cell. This is a reference to a cell style contained in the workbook object.- See Also:
-
getEncoding
public short getEncoding()Deprecated.As of 3-Jan-06 POI now automatically handles Unicode without forcing the encoding.used for internationalization, currently -1 for unchanged, 0 for compressed unicode or 1 for 16-bit- Returns:
- -1, 1 or 0 for unchanged, compressed or uncompressed (used only with String type)
- See Also:
-
setEncoding
public void setEncoding(short encoding) Deprecated.As of 3-Jan-06 POI now automatically handles Unicode without forcing the 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:
-
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.
-
setAsActiveCell
public void setAsActiveCell()Sets this cell as the active cell for the worksheet -
toString
Returns a string representation of the cell This method returns a simple representation, anthing more complex should be in user code, with knowledge of the semantics of the sheet being processed. Formula cells return the formula string, rather than the formula result. Dates are displayed in dd-MMM-yyyy format Errors are displayed as #ERR<errIdx> -
setCellComment
Assign a comment to this cell- Parameters:
comment- comment associated with this cell
-
getCellComment
Returns comment associated with this cell- Returns:
- comment associated with this cell
-
findCellComment
Cell comment finder. Returns cell comment for the specified sheet, row and column.- Returns:
- cell comment or
nullif not found
-