public final class XSSFCell extends CellBase
Cells can be numeric, formula-based or string-based (text). The cell type specifies this. String cells cannot contain 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.
Modifier | Constructor and Description |
---|---|
protected |
XSSFCell(XSSFRow row,
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
Construct a XSSFCell.
|
Modifier and Type | Method and Description |
---|---|
protected void |
applyDefaultCellStyleIfNecessary() |
void |
copyCellFrom(Cell srcCell,
CellCopyPolicy policy)
Copy cell value, formula and style, from srcCell per cell copy policy
If srcCell is null, clears the cell value and cell style per cell copy policy
This does not shift references in formulas.
|
CellRangeAddress |
getArrayFormulaRange() |
boolean |
getBooleanCellValue()
Get the value of the cell as a boolean.
|
CellType |
getCachedFormulaResultType()
Only valid for formula cells
|
XSSFComment |
getCellComment()
Returns cell comment associated with this cell
|
String |
getCellFormula()
Return a formula for the cell, for example,
SUM(C4:E4) |
protected String |
getCellFormula(BaseXSSFEvaluationWorkbook fpb)
package/hierarchy use only - reuse an existing evaluation workbook if available for caching
|
XSSFCellStyle |
getCellStyle()
Return the cell's style.
|
CellType |
getCellType()
Return the cell type.
|
int |
getColumnIndex()
Returns column index of this cell
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell |
getCTCell()
Returns the xml bean containing information about the cell's location (reference), value,
data type, formatting, and formula
|
Date |
getDateCellValue()
Get the value of the cell as a date.
|
String |
getErrorCellString()
Returns the error message, such as #VALUE!
|
byte |
getErrorCellValue()
Get the value of the cell as an error code.
|
XSSFHyperlink |
getHyperlink()
Returns hyperlink associated with this cell
|
LocalDateTime |
getLocalDateTimeCellValue()
Get the value of the cell as a LocalDateTime.
|
double |
getNumericCellValue()
Get the value of the cell as a number.
|
String |
getRawValue()
Returns the raw, underlying ooxml value for the cell
|
String |
getReference()
Returns an A1 style reference to the location of this cell
|
XSSFRichTextString |
getRichStringCellValue()
Get the value of the cell as a XSSFRichTextString
|
XSSFRow |
getRow()
Returns the row this cell belongs to
|
int |
getRowIndex()
Returns row index of a row in the sheet that contains this cell
|
protected SharedStringsTable |
getSharedStringSource() |
XSSFSheet |
getSheet()
Returns the sheet this cell belongs to
|
protected SpreadsheetVersion |
getSpreadsheetVersion() |
String |
getStringCellValue()
Get the value of the cell as a string
|
protected StylesTable |
getStylesSource() |
boolean |
isPartOfArrayFormulaGroup() |
void |
removeCellComment()
Removes the comment for this cell, if there is one.
|
protected void |
removeFormulaImpl() |
void |
removeHyperlink()
Removes the hyperlink for this cell, if there is one.
|
void |
setAsActiveCell() |
void |
setCellComment(Comment comment)
Assign a comment to this cell.
|
void |
setCellErrorValue(byte errorCode)
Set an error value for the cell
|
void |
setCellErrorValue(FormulaError error)
Set an error value for the cell
|
protected void |
setCellFormulaImpl(String formula)
Sets formula for this cell.
|
protected void |
setCellNum(int num)
Sets column index of this cell
|
void |
setCellStyle(CellStyle style)
Set the style for the cell.
|
protected void |
setCellType(CellType cellType,
BaseXSSFEvaluationWorkbook evalWb)
Needed by bug #62834, which points out getCellFormula() expects an evaluation context or creates a new one,
so if there is one in use, it needs to be carried on through.
|
protected void |
setCellTypeImpl(CellType cellType) |
void |
setCellValue(boolean value)
Set a boolean value for the cell
|
protected void |
setCellValueImpl(Calendar value) |
protected void |
setCellValueImpl(Date value) |
void |
setCellValueImpl(double value) |
protected void |
setCellValueImpl(LocalDateTime value) |
protected void |
setCellValueImpl(RichTextString str) |
protected void |
setCellValueImpl(String value) |
void |
setCTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
Set a new internal xml bean.
|
void |
setHyperlink(Hyperlink hyperlink)
Assign a hyperlink to this cell.
|
String |
toString()
Returns a string representation of the cell
|
void |
updateCellReferencesForShifting(String msg) |
getAddress, getValueType, removeFormula, setBlank, setCellFormula, setCellType, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, tryToDeleteArrayFormula
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setCellValue
protected XSSFCell(XSSFRow row, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
row
- the parent row.cell
- the xml bean containing information about the cell.protected SpreadsheetVersion getSpreadsheetVersion()
getSpreadsheetVersion
in class CellBase
@Beta public void copyCellFrom(Cell srcCell, CellCopyPolicy policy)
XSSFRowShifter
to shift references in formulas.srcCell
- The cell to take value, formula and style frompolicy
- The policy for copying the information, see CellCopyPolicy
IllegalArgumentException
- if copy cell style and srcCell is from a different workbookCellUtil.copyCell(Cell, Cell, CellCopyPolicy, CellCopyContext)
protected SharedStringsTable getSharedStringSource()
protected StylesTable getStylesSource()
public XSSFSheet getSheet()
public XSSFRow getRow()
public boolean getBooleanCellValue()
For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
IllegalStateException
- if the cell type returned by getCellType()
is not CellType.BOOLEAN
, CellType.BLANK
or CellType.FORMULA
public void setCellValue(boolean value)
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.public double getNumericCellValue()
For strings we throw an exception. For blank cells we return a 0. For formulas or error cells we return the precalculated value;
IllegalStateException
- if the cell type returned by getCellType()
is CellType.STRING
NumberFormatException
- if the cell value isn't a parsable double
.for turning this number into a string similar to that which Excel would render this number as.
public void setCellValueImpl(double value)
setCellValueImpl
in class CellBase
public String getStringCellValue()
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
public XSSFRichTextString getRichStringCellValue()
For 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
protected void setCellValueImpl(String value)
setCellValueImpl
in class CellBase
protected void setCellValueImpl(RichTextString str)
setCellValueImpl
in class CellBase
public String getCellFormula()
SUM(C4:E4)
IllegalStateException
- if the cell type returned by getCellType()
is not CellType.FORMULA
protected String getCellFormula(BaseXSSFEvaluationWorkbook fpb)
fpb
- evaluation workbook for reuse, if available, or null to create a new one as neededIllegalStateException
- if the cell type returned by getCellType()
is not CellType.FORMULA
protected void setCellFormulaImpl(String formula)
Note, this method only sets the formula string and does not calculate the formula value.
To set the precalculated value use CellBase.setCellValue(double)
or CellBase.setCellValue(String)
Note, if there are any shared formulas, his will invalidate any
FormulaEvaluator
instances based on this workbook.
setCellFormulaImpl
in class CellBase
formula
- the formula to set, e.g. "SUM(C4:E4)"
.
If the argument is null
then the current formula is removed.FormulaParseException
- if the formula has incorrect syntax or is otherwise invalidIllegalStateException
- if the operation is not allowed, for example,
when the cell is a part of a multi-cell array formulaprotected void removeFormulaImpl()
removeFormulaImpl
in class CellBase
public int getColumnIndex()
public int getRowIndex()
public String getReference()
public XSSFCellStyle getCellStyle()
protected void applyDefaultCellStyleIfNecessary()
public void setCellStyle(CellStyle style)
Set the style for the cell. The style should be an XSSFCellStyle created/retrieved from the XSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style,
use CellUtil.setCellStyleProperties(Cell, java.util.Map)
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.IllegalArgumentException
- if style belongs to a different styles source (most likely because style is from a different Workbook)public CellType getCellType()
CellType.FORMULA
for all cells, even though the formula is only defined
in the OOXML file for the top left cell of the array.
NOTE: POI does not support data table formulas. Cells in a data table appear to POI as plain cells typed from their cached value.
public CellType getCachedFormulaResultType()
CellType.NUMERIC
, CellType.STRING
,
CellType.BOOLEAN
, CellType.ERROR
) depending
on the cached value of the formulapublic Date getDateCellValue()
For strings we throw an exception. For blank cells we return a null.
IllegalStateException
- if the cell type returned by getCellType()
is CellType.STRING
NumberFormatException
- if the cell value isn't a parsable double
.for formatting this date into a string similar to how excel does.
public LocalDateTime getLocalDateTimeCellValue()
For strings we throw an exception. For blank cells we return a null.
IllegalStateException
- if the cell type returned by getCellType()
is CellType.STRING
NumberFormatException
- if the cell value isn't a parsable double
.for formatting this date into a string similar to how excel does.
protected void setCellValueImpl(Date value)
setCellValueImpl
in class CellBase
protected void setCellValueImpl(LocalDateTime value)
setCellValueImpl
in class CellBase
protected void setCellValueImpl(Calendar value)
setCellValueImpl
in class CellBase
public String getErrorCellString() throws IllegalStateException
IllegalStateException
- if the cell type returned by getCellType()
isn't CellType.ERROR
FormulaError
public byte getErrorCellValue() throws IllegalStateException
For strings, numbers, and booleans, we throw an exception. For blank cells we return a 0.
IllegalStateException
- if the cell type returned by getCellType()
isn't #ERROR
FormulaError
public void setCellErrorValue(byte errorCode)
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.FormulaError
public void setCellErrorValue(FormulaError error)
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.public void setAsActiveCell()
protected void setCellNum(int num)
num
- column index of this cellprotected void setCellTypeImpl(CellType cellType)
setCellTypeImpl
in class CellBase
protected void setCellType(CellType cellType, BaseXSSFEvaluationWorkbook evalWb)
evalWb
- BaseXSSFEvaluationWorkbook already in use, or null if a new implicit one should be usedpublic String toString()
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>
public String getRawValue()
If the cell contains a string, then this value is an index into the shared string table, pointing to the actual string value. Otherwise, the value of the cell is expressed directly in this element. Cells containing formulas express the last calculated result of the formula in this element.
null
for blank cells.public XSSFComment getCellComment()
null
public void setCellComment(Comment comment)
comment
- the XSSFComment associated with this cellpublic void removeCellComment()
public XSSFHyperlink getHyperlink()
null
if not foundpublic void setHyperlink(Hyperlink hyperlink)
hyperlink
- the hyperlink to associate with this cellpublic void removeHyperlink()
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell getCTCell()
@Internal public void setCTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
public CellRangeAddress getArrayFormulaRange()
public boolean isPartOfArrayFormulaGroup()
public void updateCellReferencesForShifting(String msg)