Class XSSFCell
- All Implemented Interfaces:
Cell
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidcopyCellFrom(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.Only valid for array formula cellsbooleanGet the value of the cell as a boolean.Only valid for formula cellsReturns cell comment associated with this cellReturn a formula for the cell, for example,SUM(C4:E4)protected Stringpackage/hierarchy use only - reuse an existing evaluation workbook if available for cachingReturn the cell's style.Return the cell type.intReturns column index of this cellorg.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellReturns the xml bean containing information about the cell's location (reference), value, data type, formatting, and formulaGet the value of the cell as a date.Returns the error message, such as #VALUE!byteGet the value of the cell as an error code.Returns hyperlink associated with this cellGet the value of the cell as a LocalDateTime.doubleGet the value of the cell as a number.Returns the raw, underlying ooxml value for the cellReturns an A1 style reference to the location of this cellGet the value of the cell as a XSSFRichTextStringgetRow()Returns the row this cell belongs tointReturns row index of a row in the sheet that contains this cellprotected SharedStringsTablegetSheet()Returns the sheet this cell belongs toprotected SpreadsheetVersionGet the spreadsheet version for the given implementation.Get the value of the cell as a stringprotected StylesTablebooleanvoidRemoves the comment for this cell, if there is one.protected voidImplementation-specific removal of the formula.voidRemoves the hyperlink for this cell, if there is one.voidSets this cell as the active cell for the worksheetvoidsetCellComment(Comment comment) Assign a comment to this cell.voidsetCellErrorValue(byte errorCode) Set an error value for the cellvoidsetCellErrorValue(FormulaError error) Set an error value for the cellprotected voidsetCellFormulaImpl(String formula) Sets formula for this cell.protected voidsetCellNum(int num) Sets column index of this cellvoidsetCellStyle(CellStyle style) Set the style for the cell.protected voidsetCellType(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 voidsetCellTypeImpl(CellType cellType) Implementation-specific logicvoidsetCellValue(boolean value) Set a boolean value for the cellvoidsetCellValueImpl(double value) Implementation-specific way to set a numeric value.protected voidsetCellValueImpl(String value) Implementation-specific way to set a string value.protected voidsetCellValueImpl(LocalDateTime value) Implementation-specific way to set a date value.protected voidsetCellValueImpl(Calendar value) Implementation-specific way to set a calendar value.protected voidsetCellValueImpl(Date value) Implementation-specific way to set a date value.protected voidImplementation-specific way to set a RichTextString value.voidsetCTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell) Set a new internal xml bean.voidsetHyperlink(Hyperlink hyperlink) Assign a hyperlink to this cell.toString()Returns a string representation of the cellvoidMethods inherited from class org.apache.poi.ss.usermodel.CellBase
getAddress, getValueType, removeFormula, setBlank, setCellFormula, setCellType, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, tryToDeleteArrayFormulaMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.poi.ss.usermodel.Cell
setCellValue
-
Constructor Details
-
XSSFCell
Construct a XSSFCell.- Parameters:
row- the parent row.cell- the xml bean containing information about the cell.
-
-
Method Details
-
getSpreadsheetVersion
Description copied from class:CellBaseGet the spreadsheet version for the given implementation.- Specified by:
getSpreadsheetVersionin classCellBase- Returns:
- the spreadsheet version
-
copyCellFrom
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. UseXSSFRowShifterto shift references in formulas.- Parameters:
srcCell- The cell to take value, formula and style frompolicy- The policy for copying the information, seeCellCopyPolicy- Throws:
IllegalArgumentException- if copy cell style and srcCell is from a different workbook- See Also:
-
getStylesSource
- Returns:
- table of cell styles shared across this workbook
-
getSheet
Returns the sheet this cell belongs to- Returns:
- the sheet this cell belongs to
-
getRow
Returns the row this cell belongs to- Returns:
- the row this cell belongs to
-
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.
- Returns:
- the value of the cell as a boolean
- Throws:
IllegalStateException- if the cell type returned bygetCellType()is notCellType.BOOLEAN,CellType.BLANKorCellType.FORMULA
-
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.
-
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;
- Returns:
- the value of the cell as a number
- Throws:
IllegalStateException- if the cell type returned bygetCellType()isCellType.STRINGNumberFormatException- if the cell value isn't a parsabledouble.- See Also:
-
setCellValueImpl
public void setCellValueImpl(double value) Description copied from class:CellBaseImplementation-specific way to set a numeric value.valueis guaranteed to be a valid (non-NaN) double. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would returnCellType.NUMERIC.- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new value to set
-
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
- Returns:
- the value of the cell as a string
-
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
- Returns:
- the value of the cell as a XSSFRichTextString
-
setCellValueImpl
Description copied from class:CellBaseImplementation-specific way to set a string value. The value is guaranteed to be non-null and to satisfy the length limitation imposed by the spreadsheet version. The implementation is expected to adjust cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() (whichever appropriate) would returnCellType.STRING.- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new value to set.
-
setCellValueImpl
Description copied from class:CellBaseImplementation-specific way to set a RichTextString value. The value is guaranteed to be non-null, having non-null value, and to satisfy the length limitation imposed by the spreadsheet version. The implementation is expected to adjust cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() (whichever appropriate) would returnCellType.STRING.- Specified by:
setCellValueImplin classCellBase- Parameters:
str- the new value to set.
-
getCellFormula
Return a formula for the cell, for example,SUM(C4:E4)- Returns:
- a formula for the cell
- Throws:
IllegalStateException- if the cell type returned bygetCellType()is notCellType.FORMULA
-
getCellFormula
package/hierarchy use only - reuse an existing evaluation workbook if available for caching- Parameters:
fpb- evaluation workbook for reuse, if available, or null to create a new one as needed- Returns:
- a formula for the cell
- Throws:
IllegalStateException- if the cell type returned bygetCellType()is notCellType.FORMULA
-
setCellFormulaImpl
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
CellBase.setCellValue(double)orCellBase.setCellValue(String)Note, if there are any shared formulas, his will invalidate any
FormulaEvaluatorinstances based on this workbook.- Specified by:
setCellFormulaImplin classCellBase- Parameters:
formula- the formula to set, e.g."SUM(C4:E4)". If the argument isnullthen the current formula is removed.- Throws:
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 formula
-
removeFormulaImpl
protected void removeFormulaImpl()Description copied from class:CellBaseImplementation-specific removal of the formula. The cell is guaranteed to have a regular formula set. Shall preserve the "cached" value.- Specified by:
removeFormulaImplin classCellBase
-
getColumnIndex
public int getColumnIndex()Returns column index of this cell- 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- Returns:
- zero-based row index of a row in the sheet that contains this cell
-
getReference
Returns an A1 style reference to the location of this cell- Returns:
- A1 style reference to the location of this cell
-
getCellStyle
Return the cell's style. Since POI v5.2.3, this returns the column style if the cell has no style of its own. If no column default style is set, the row default style is checked. This method has always fallen back to return the default style if there is no other style to return.- Returns:
- the cell's style.
- See Also:
-
applyDefaultCellStyleIfNecessary
protected void applyDefaultCellStyleIfNecessary() -
setCellStyle
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.setCellStylePropertiesEnum(Cell, java.util.Map)- Parameters:
style- reference contained in the workbook. If the value is null then the style information is removed causing the cell to use the default workbook style.- Throws:
IllegalArgumentException- if style belongs to a different styles source (most likely because style is from a different Workbook)- See Also:
-
getCellType
Return the cell type. Tables in an array formula returnCellType.FORMULAfor 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.
- Returns:
- the cell type
-
getCachedFormulaResultType
Only valid for formula cells- Returns:
- one of (
CellType.NUMERIC,CellType.STRING,CellType.BOOLEAN,CellType.ERROR) depending on the cached value of the formula
-
getDateCellValue
Get the value of the cell as a date.For strings we throw an exception. For blank cells we return a null.
- Returns:
- the value of the cell as a date
- Throws:
IllegalStateException- if the cell type returned bygetCellType()isCellType.STRINGNumberFormatException- if the cell value isn't a parsabledouble.- See Also:
-
getLocalDateTimeCellValue
Get the value of the cell as a LocalDateTime.For strings we throw an exception. For blank cells we return a null.
- Returns:
- the value of the cell as a LocalDateTime
- Throws:
IllegalStateException- if the cell type returned bygetCellType()isCellType.STRINGNumberFormatException- if the cell value isn't a parsabledouble.- See Also:
-
setCellValueImpl
Description copied from class:CellBaseImplementation-specific way to set a date value.valueis guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would returnCellType.NUMERIC.- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new date to set
-
setCellValueImpl
Description copied from class:CellBaseImplementation-specific way to set a date value.valueis guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would returnCellType.NUMERIC.- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new date to set
-
setCellValueImpl
Description copied from class:CellBaseImplementation-specific way to set a calendar value.valueis guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would returnCellType.NUMERIC.- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new calendar value to set
-
getErrorCellString
Returns the error message, such as #VALUE!- Returns:
- the error message such as #VALUE!
- Throws:
IllegalStateException- if the cell type returned bygetCellType()isn'tCellType.ERROR- See Also:
-
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.
- Returns:
- the value of the cell as an error code
- Throws:
IllegalStateException- if the cell type returned bygetCellType()isn't#ERROR- See Also:
-
setCellErrorValue
public void setCellErrorValue(byte errorCode) Set an error value for the cell- 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.- See Also:
-
setCellErrorValue
Set an 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.
-
setAsActiveCell
public void setAsActiveCell()Description copied from interface:CellSets this cell as the active cell for the worksheet -
setCellNum
protected void setCellNum(int num) Sets column index of this cell- Parameters:
num- column index of this cell
-
setCellTypeImpl
Description copied from class:CellBaseImplementation-specific logic- Specified by:
setCellTypeImplin classCellBase- Parameters:
cellType- new cell type. Guaranteed non-null, not _NONE.
-
setCellType
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.- Parameters:
evalWb- BaseXSSFEvaluationWorkbook already in use, or null if a new implicit one should be used
-
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>
-
getRawValue
Returns the raw, underlying ooxml value for the cellIf 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.
- Returns:
- the raw cell value as contained in the underlying CTCell bean,
nullfor blank cells.
-
getCellComment
Returns cell comment associated with this cell- Returns:
- the cell comment associated with this cell or
null
-
setCellComment
Assign a comment to this cell. If the supplied comment is null, the comment for this cell will be removed.- Parameters:
comment- the XSSFComment associated with this cell
-
removeCellComment
public void removeCellComment()Removes the comment for this cell, if there is one. -
getHyperlink
Returns hyperlink associated with this cell- Returns:
- hyperlink associated with this cell or
nullif not found
-
setHyperlink
Assign a hyperlink to this cell. If the supplied hyperlink is null, the hyperlink for this cell will be removed.- Parameters:
hyperlink- the hyperlink to associate with this cell
-
removeHyperlink
public void removeHyperlink()Removes the hyperlink for this cell, if there is one. -
getCTCell
Returns the xml bean containing information about the cell's location (reference), value, data type, formatting, and formula- Returns:
- the xml bean containing information about this cell
-
setCTCell
Set a new internal xml bean. This is only for internal use, do not call this from outside! This is necessary in some rare cases to work around XMLBeans specialties. -
getArrayFormulaRange
Description copied from interface:CellOnly valid for array formula cells- Returns:
- range of the array formula group that the cell belongs to.
-
isPartOfArrayFormulaGroup
public boolean isPartOfArrayFormulaGroup()- Returns:
trueif this cell is part of group of cells having a common array formula.
-
updateCellReferencesForShifting
-