Class SXSSFCell
- All Implemented Interfaces:
Cell
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the address of this cellOnly valid for array formula cellsboolean
Get the value of the cell as a boolean.Only valid for formula cellsDeprecated.Returns comment associated with this cellReturn a formula for the cell, for example,SUM(C4:E4)
Return the cell's style.Return the cell type.Deprecated.usegetCellType
insteadint
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 XSSFRichTextStringgetRow()
Returns the Row this cell belongs toint
Returns row index of a row in the sheet that contains this cellgetSheet()
Returns the sheet this cell belongs toGet the value of the cell as a stringboolean
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 cellvoid
setCellErrorValue
(byte value) Set a error value for the cellvoid
setCellFormula
(String formula) Sets formula for this cell.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) Converts the supplied date to its equivalent Excel numeric value and sets that into the cell.void
setCellValue
(RichTextString value) Set a rich string value for the cell.void
setHyperlink
(Hyperlink link) Assign a hyperlink to this cell.toString()
Returns a string representation of the cell
-
Constructor Details
-
SXSSFCell
-
-
Method Details
-
getColumnIndex
public int getColumnIndex()Returns column index of this cell- Specified by:
getColumnIndex
in interfaceCell
- Returns:
- zero-based column index of a column in a sheet.
-
getRowIndex
public int getRowIndex()Returns row index of a row in the sheet that contains this cell- Specified by:
getRowIndex
in interfaceCell
- Returns:
- zero-based row index of a row in the sheet that contains this cell
-
getAddress
Gets the address of this cell- Specified by:
getAddress
in interfaceCell
- Returns:
A1
style address of this cell
-
getSheet
Returns the sheet this cell belongs to -
getRow
Returns the Row this cell belongs to -
setCellType
Set the cells type (numeric, formula or string)- Specified by:
setCellType
in interfaceCell
- Throws:
IllegalArgumentException
- if the specified cell type is invalid
-
getCellType
Return the cell type.- Specified by:
getCellType
in interfaceCell
- Returns:
- the cell type
-
getCellTypeEnum
Deprecated.usegetCellType
insteadReturn the cell type.- Specified by:
getCellTypeEnum
in interfaceCell
- Returns:
- the cell type
- Since:
- POI 3.15 beta 3
-
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
-
getCachedFormulaResultTypeEnum
Deprecated.usegetCachedFormulaResultType
insteadOnly 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
-
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
Converts the supplied date to its equivalent Excel numeric value and sets that into the cell.Note - There is actually no 'DATE' cell type in Excel. In many cases (when entering date values), Excel automatically adjusts the cell style to some date format, creating the illusion that the cell data type is now something besides
CellType.NUMERIC
. POI does not attempt to replicate this behaviour. To make a numeric cell display as a date, usesetCellStyle(CellStyle)
etc.- 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 numerics 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 using
setCellValue(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 rich 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 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 is null then we will change the cell to a Blank cell.
-
setCellFormula
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
setCellValue(double)
orsetCellValue(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.- Throws:
FormulaParseException
- if the formula has incorrect syntax or is otherwise invalid
-
getCellFormula
Return a formula for the cell, for example,SUM(C4:E4)
- Specified by:
getCellFormula
in interfaceCell
- Returns:
- a formula for the cell
- Throws:
IllegalStateException
- if the cell type returned bygetCellType()
is not CellType.FORMULA
-
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. For formulas or error cells we return the precalculated value;
- Specified by:
getNumericCellValue
in interfaceCell
- Returns:
- the value of the cell as a number
- Throws:
IllegalStateException
- if the cell type returned bygetCellType()
is CellType.STRINGNumberFormatException
- if the cell value isn't a parsabledouble
.- 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.
- Specified by:
getDateCellValue
in interfaceCell
- Returns:
- the value of the cell as a date
- Throws:
IllegalStateException
- if the cell type returned bygetCellType()
is CellType.STRINGNumberFormatException
- if the cell value isn't a parsabledouble
.- See Also:
-
getRichStringCellValue
Get the value of the cell as a XSSFRichTextStringFor numeric cells we throw an exception. For blank cells we return an empty string. For formula cells we return the pre-calculated value if a string, otherwise an exception.
- Specified by:
getRichStringCellValue
in interfaceCell
- Returns:
- the value of the cell as a XSSFRichTextString
-
getStringCellValue
Get the value of the cell as a stringFor 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
-
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 value) Set a error value for the cell- Specified by:
setCellErrorValue
in interfaceCell
- Parameters:
value
- 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.- See Also:
-
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
- Throws:
IllegalStateException
- if the cell type returned bygetCellType()
is not CellType.BOOLEAN, CellType.BLANK or CellType.FORMULA
-
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
- Throws:
IllegalStateException
- if the cell type returned bygetCellType()
isn't CellType.ERROR- See Also:
-
setCellStyle
Set the style for the cell. The style should be an CellStyle created/retreived from the Workbook.
To change the style of a cell without affecting other cells that use the same style, use
CellUtil.setCellStyleProperties(Cell, Map)
- Specified by:
setCellStyle
in interfaceCell
- Parameters:
style
- reference contained in the workbook. If the value is null then the style information is removed causing the cell to used the default workbook style.- See Also:
-
getCellStyle
Return the cell's style.- 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:
-
setAsActiveCell
public void setAsActiveCell()Sets this cell as the active cell for the worksheet- Specified by:
setAsActiveCell
in interfaceCell
-
setCellComment
Assign a comment to this cell- 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 or
null
if not found
-
removeCellComment
public void removeCellComment()Removes the comment for this cell, if there is one.- 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:
link
- hyperlink associated with this cell
-
removeHyperlink
public void removeHyperlink()Removes the hyperlink for this cell, if there is one.- Specified by:
removeHyperlink
in interfaceCell
-
getArrayFormulaRange
Only valid for array formula cells- Specified by:
getArrayFormulaRange
in interfaceCell
- Returns:
- range of the array formula group that the cell belongs to.
-
isPartOfArrayFormulaGroup
- Specified by:
isPartOfArrayFormulaGroup
in interfaceCell
- Returns:
true
if this cell is part of group of cells having a common array formula.
-
toString
Returns a string representation of the cellFormula cells return the formula string, rather than the formula result. Dates are displayed in dd-MMM-yyyy format Errors are displayed as #ERR<errIdx>
-
getCachedFormulaResultType
instead