Class HSSFCell
- All Implemented Interfaces:
Cell
Cells should have their number (0 based) before being added to a row. Only cells that have values should be added.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final short
static final short
static final short
static final int
The maximum number of columns in BIFF8 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
HSSFCell
(HSSFWorkbook book, HSSFSheet sheet, int row, short col) Creates new Cell - Should only be called by HSSFRow.protected
HSSFCell
(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type) Creates new Cell - Should only be called by HSSFRow.protected
HSSFCell
(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval) Creates an HSSFCell from a CellValueRecordInterface. -
Method Summary
Modifier and TypeMethodDescriptionGets the address of this cellOnly valid for array formula cellsboolean
get the value of the cell as a boolean.protected InternalWorkbook
Returns the Workbook that this Cell is bound toOnly valid for formula cellsDeprecated.Returns comment associated with this cellReturn a formula for the cell, for example,SUM(C4:E4)
get the style for the cell.get the cells type (numeric, formula or string)Deprecated.protected CellValueRecordInterface
Should only be used by HSSFSheet and friends.int
Returns column index of this cellGet the value of the cell as a date.byte
get the value of the cell as an error code.double
Get the value of the cell as a number.get the value of the cell as a string - for numeric cells we throw an exception.getRow()
Returns the HSSFRow this cell belongs toint
Returns row index of a row in the sheet that contains this cellgetSheet()
Returns the HSSFSheet this cell belongs toget the value of the cell as a string - for numeric cells we throw an exception.boolean
void
Removes the comment for this cell, if there is one.void
Removes the hyperlink for this cell, if there is one.void
Sets this cell as the active cell for the worksheetvoid
setCellComment
(Comment comment) Assign a comment to this cell.void
setCellErrorValue
(byte errorCode) Deprecated.3.15 beta 2.void
setCellErrorValue
(FormulaError error) set a error value for the cellvoid
setCellFormula
(String formula) Sets formula for this cell.void
setCellStyle
(HSSFCellStyle style) void
setCellStyle
(CellStyle style) Set the style for the cell.void
setCellType
(CellType cellType) Set the cells type (numeric, formula or string).void
setCellValue
(boolean value) set a boolean value for the cellvoid
setCellValue
(double value) set a numeric value for the cellvoid
setCellValue
(String value) set a string value for the cell.void
setCellValue
(Calendar value) set a date value for the cell.void
setCellValue
(Date value) set a date value for the cell.void
setCellValue
(RichTextString value) Set a string value for the cell.void
setHyperlink
(Hyperlink hyperlink) Assign a hyperlink to this cell.toString()
Returns a string representation of the cell This method returns a simple representation, anything more complex should be in user code, with knowledge of the semantics of the sheet being processed.protected void
updateCellNum
(short num) Updates the cell record's idea of what column it belongs in (0 based)
-
Field Details
-
LAST_COLUMN_NUMBER
public static final int LAST_COLUMN_NUMBERThe maximum number of columns in BIFF8 -
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
CellType.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
- - 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
-
getSheet
Returns the HSSFSheet this cell belongs to -
getRow
Returns the HSSFRow this cell belongs to -
getBoundWorkbook
Returns the Workbook that this Cell is bound to -
getRowIndex
public int getRowIndex()Description copied from interface:Cell
Returns row index of a row in the sheet that contains this cell- Specified by:
getRowIndex
in interfaceCell
- Returns:
- the (zero based) index of the row containing this cell
-
updateCellNum
protected void updateCellNum(short num) Updates the cell record's idea of what column it belongs in (0 based)- Parameters:
num
- the new cell number
-
getColumnIndex
public int getColumnIndex()Description copied from interface:Cell
Returns column index of this cell- Specified by:
getColumnIndex
in interfaceCell
- Returns:
- zero-based column index of a column in a sheet.
-
getAddress
Gets the address of this cell- Specified by:
getAddress
in interfaceCell
- Returns:
A1
style address of this cell
-
setCellType
Set the cells type (numeric, formula or string). If the cell currently contains a value, the value will be converted to match the new type, if possible.- Specified by:
setCellType
in interfaceCell
-
getCellType
get the cells type (numeric, formula or string)- Specified by:
getCellType
in interfaceCell
- Returns:
- the cell type
-
getCellTypeEnum
Deprecated.get the cells type (numeric, formula or string)- Specified by:
getCellTypeEnum
in interfaceCell
- Returns:
- the cell type
- Since:
- POI 3.15 beta 3
-
setCellValue
public void setCellValue(double value) set a numeric value for the cell- Specified by:
setCellValue
in interfaceCell
- 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.- Specified by:
setCellValue
in interfaceCell
- 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. This will set the cell value based on the Calendar's timezone. As Excel does not support timezones this means that both 20:00+03:00 and 20:00-03:00 will be reported as the same value (20:00) even that there are 6 hours difference between the two times. This difference can be preserved by usingsetCellValue(value.getTime())
which will automatically shift the times to the default timezone.- Specified by:
setCellValue
in interfaceCell
- 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
set a string value for the cell.- Specified by:
setCellValue
in interfaceCell
- Parameters:
value
- value to set the cell to. For formulas we'll set the formula cached string result, 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.- Specified by:
setCellValue
in interfaceCell
- 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 isnull
then we will change the cell to a Blank cell.
-
setCellFormula
Description copied from interface:Cell
Sets formula for this cell.Note, this method only sets the formula string and does not calculate the formula value. To set the precalculated value use
Cell.setCellValue(double)
orCell.setCellValue(String)
- Specified by:
setCellFormula
in interfaceCell
- Parameters:
formula
- the formula to set, e.g."SUM(C4:E4)"
. If the argument isnull
then the current formula is removed.
-
getCellFormula
Description copied from interface:Cell
Return a formula for the cell, for example,SUM(C4:E4)
- Specified by:
getCellFormula
in interfaceCell
- Returns:
- a formula for the 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. SeeHSSFDataFormatter
for turning this number into a string similar to that which Excel would render this number as.- Specified by:
getNumericCellValue
in interfaceCell
- Returns:
- the value of the cell as a number
- See Also:
-
getDateCellValue
Get the value of the cell as a date. For strings we throw an exception. For blank cells we return a null. SeeHSSFDataFormatter
for formatting this date into a string similar to how excel does.- Specified by:
getDateCellValue
in interfaceCell
- Returns:
- the value of the cell as a date
- See Also:
-
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. For formulaCells that are not string Formulas, we throw an exception- Specified by:
getStringCellValue
in interfaceCell
- Returns:
- the value of the cell as a 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 throw an exception- Specified by:
getRichStringCellValue
in interfaceCell
- Returns:
- the value of the cell as a XSSFRichTextString
-
setCellValue
public void setCellValue(boolean value) set a boolean value for the cell- Specified by:
setCellValue
in interfaceCell
- 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 errorCode) Deprecated.3.15 beta 2. UsesetCellErrorValue(FormulaError)
instead.set a error value for the cell- Specified by:
setCellErrorValue
in interfaceCell
- Parameters:
errorCode
- the error value to set this cell to. For formulas we'll set the precalculated value , for errors we'll set its value. For other types we will change the cell to an error cell and set its value. For error code byte, seeFormulaError
.- See Also:
-
setCellErrorValue
set a error value for the cell- Parameters:
error
- the error value to set this cell to. For formulas we'll set the precalculated value , 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.- Specified by:
getBooleanCellValue
in interfaceCell
- Returns:
- the value of the cell as a boolean
-
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.- Specified by:
getErrorCellValue
in interfaceCell
- Returns:
- the value of the cell as an error code
- See Also:
-
setCellStyle
Set the style for the cell. The style should be an HSSFCellStyle created/retreived from the HSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style, use
CellUtil.setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, java.util.Map)
- Specified by:
setCellStyle
in interfaceCell
- Parameters:
style
- reference contained in the workbook- See Also:
-
setCellStyle
-
getCellStyle
get the style for the cell. This is a reference to a cell style contained in the workbook object.- Specified by:
getCellStyle
in interfaceCell
- Returns:
- the cell's style. Always not-null. Default cell style has zero index and can be obtained as
workbook.getCellStyleAt(0)
- 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- Specified by:
setAsActiveCell
in interfaceCell
-
toString
Returns a string representation of the cell This method returns a simple representation, anything 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. If the supplied comment is null, the comment for this cell will be removed.- Specified by:
setCellComment
in interfaceCell
- Parameters:
comment
- comment associated with this cell
-
getCellComment
Returns comment associated with this cell- Specified by:
getCellComment
in interfaceCell
- Returns:
- comment associated with this cell
-
removeCellComment
public void removeCellComment()Removes the comment for this cell, if there is one. WARNING - some versions of excel will loose all comments after performing this action!- Specified by:
removeCellComment
in interfaceCell
-
getHyperlink
- Specified by:
getHyperlink
in interfaceCell
- Returns:
- hyperlink associated with this cell or
null
if not found
-
setHyperlink
Assign a hyperlink to this cell. If the supplied hyperlink is null, the hyperlink for this cell will be removed.- Specified by:
setHyperlink
in interfaceCell
- Parameters:
hyperlink
- hyperlink associated with this cell
-
removeHyperlink
public void removeHyperlink()Removes the hyperlink for this cell, if there is one.- Specified by:
removeHyperlink
in interfaceCell
-
getCachedFormulaResultType
Only valid for formula cells- Specified by:
getCachedFormulaResultType
in interfaceCell
- Returns:
- one of (
CellType.NUMERIC
,CellType.STRING
,CellType.BOOLEAN
,CellType.ERROR
) depending on the cached value of the formula - Since:
- POI 4.0
-
getCachedFormulaResultTypeEnum
Deprecated.usegetCachedFormulaResultType
Will be deleted when we make the CellType enum transition. See bug 59791.Only valid for formula cells- Specified by:
getCachedFormulaResultTypeEnum
in interfaceCell
- Returns:
- one of (
CellType.NUMERIC
,CellType.STRING
,CellType.BOOLEAN
,CellType.ERROR
) depending on the cached value of the formula - Since:
- POI 3.15 beta 3
-
getArrayFormulaRange
Description copied from interface:Cell
Only valid for array formula cells- Specified by:
getArrayFormulaRange
in interfaceCell
- Returns:
- range of the array formula group that the cell belongs to.
-
isPartOfArrayFormulaGroup
public boolean isPartOfArrayFormulaGroup()- Specified by:
isPartOfArrayFormulaGroup
in interfaceCell
- Returns:
true
if this cell is part of group of cells having a common array formula.
-
getCachedFormulaResultType
Will be deleted when we make the CellType enum transition.