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 shortstatic final shortstatic final shortstatic final intThe maximum number of columns in BIFF8 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col) Creates new Cell - Should only be called by HSSFRow.protectedHSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type) Creates new Cell - Should only be called by HSSFRow.protectedHSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval) Creates an HSSFCell from a CellValueRecordInterface. -
Method Summary
Modifier and TypeMethodDescriptionOnly valid for array formula cellsbooleanget the value of the cell as a boolean.protected InternalWorkbookReturns the Workbook that this Cell is bound toOnly valid for formula cellsReturns 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)protected CellValueRecordInterfaceShould only be used by HSSFSheet and friends.intReturns column index of this cellGet the value of the cell as a date.byteget the value of the cell as an error code.Get the value of the cell as a LocalDateTime.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.getRow()Returns the HSSFRow this cell belongs tointReturns row index of a row in the sheet that contains this cellgetSheet()Returns the HSSFSheet this cell belongs toprotected SpreadsheetVersionGet the spreadsheet version for the given implementation.get the value of the cell as a string - for numeric cells we throw an exception.booleanvoidRemoves 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) Deprecated.3.15 beta 2.voidsetCellErrorValue(FormulaError error) set an error value for the cellprotected voidsetCellFormulaImpl(String formula) Implementation-specific setting the formula.voidsetCellStyle(HSSFCellStyle style) voidsetCellStyle(CellStyle style) Set the style for the cell.protected voidsetCellTypeImpl(CellType cellType) Implementation-specific logicvoidsetCellValue(boolean value) set a boolean value for the cellprotected voidsetCellValueImpl(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 voidsetCellValueImpl(RichTextString value) Implementation-specific way to set a RichTextString value.voidsetHyperlink(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 voidupdateCellNum(short num) Updates the cell record's idea of what column it belongs in (0 based)Methods 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
-
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
-
getSpreadsheetVersion
Description copied from class:CellBaseGet the spreadsheet version for the given implementation.- Specified by:
getSpreadsheetVersionin classCellBase- Returns:
- the spreadsheet version
-
getSheet
Returns the HSSFSheet this cell belongs to- Returns:
- the HSSFSheet that owns this cell
-
getRow
Returns the HSSFRow this cell belongs to- Returns:
- the HSSFRow that owns this cell
-
getBoundWorkbook
Returns the Workbook that this Cell is bound to -
getRowIndex
public int getRowIndex()Description copied from interface:CellReturns row index of a row in the sheet that contains this cell- 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:CellReturns column index of this cell- Returns:
- zero-based column index of a column in a sheet.
-
setCellTypeImpl
Description copied from class:CellBaseImplementation-specific logic- Specified by:
setCellTypeImplin classCellBase- Parameters:
cellType- new cell type. Guaranteed non-null, not _NONE.
-
getCellType
get the cells type (numeric, formula or string)- Returns:
- the cell type
-
setCellValueImpl
protected 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
-
setCellValueImpl
Implementation-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.In HSSF, only the number of days is stored. The fractional part is ignored.
- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new date to set- See Also:
-
setCellValueImpl
Implementation-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.In HSSF, only the number of days is stored. The fractional part is ignored.
- Specified by:
setCellValueImplin classCellBase- Parameters:
value- the new date to set- See Also:
-
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
-
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:
value- the new value to set.
-
setCellFormulaImpl
Description copied from class:CellBaseImplementation-specific setting the formula. Formula is not null. Shall not change the value.- Specified by:
setCellFormulaImplin classCellBase- Parameters:
formula- The text of the formula to set.
-
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
-
getCellFormula
Description copied from interface:CellReturn a formula for the cell, for example,SUM(C4:E4)- 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. SeeHSSFDataFormatterfor turning this number into a string similar to that which Excel would render this number as.- 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. SeeHSSFDataFormatterfor formatting this date into a string similar to how excel does.- Returns:
- the value of the cell as a date
- 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. SeeHSSFDataFormatterfor formatting this date into a string similar to how excel does.- Returns:
- the value of the cell as a LocalDateTime
- 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- 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- Returns:
- the value of the cell as a XSSFRichTextString
-
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
Deprecated.3.15 beta 2. UsesetCellErrorValue(FormulaError)instead.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. For error code byte, seeFormulaError.- 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.
-
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
-
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.- 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/retrieved from the HSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style, use
CellUtil.setCellStylePropertiesEnum(org.apache.poi.ss.usermodel.Cell, java.util.Map)- 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. If the cell does not have an explicit style assigned, this method will fall back to returning the column or row style (if any).- 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()Description copied from interface:CellSets this cell as the active cell for the worksheet -
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.- Parameters:
comment- comment associated with this cell
-
getCellComment
Returns comment associated with this cell- 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! -
getHyperlink
- 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- hyperlink associated with this cell
-
removeHyperlink
public void removeHyperlink()Removes the hyperlink for this cell, if there is one. -
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 - Since:
- 4.0
-
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.
-