Top Description Fields Constructors Methods
org.apache.poi.hssf.usermodel

public Class HSSFCell

extends CellBase
Class Inheritance
Imports
java.text.SimpleDateFormat, java.time.LocalDateTime, java.util.Calendar, .Date, .Iterator, .List, org.apache.poi.hssf.model.HSSFFormulaParser, .InternalWorkbook, org.apache.poi.hssf.record.BlankRecord, .BoolErrRecord, .CellValueRecordInterface, .ExtendedFormatRecord, .FormulaRecord, .HyperlinkRecord, .LabelSSTRecord, .NumberRecord, .Record, .RecordBase, org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate, org.apache.poi.hssf.record.common.UnicodeString, org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.ss.formula.FormulaType, org.apache.poi.ss.formula.eval.ErrorEval, org.apache.poi.ss.formula.ptg.ExpPtg, .Ptg, org.apache.poi.ss.usermodel.CellBase, .CellStyle, .CellType, .CellValue, .Comment, .DateUtil, .FormulaError, .Hyperlink, .RichTextString, org.apache.poi.ss.util.CellRangeAddress, .CellReference, .NumberToTextConverter, org.apache.poi.util.LocaleUtil

High level representation of a cell in a row of a spreadsheet. 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.

Field Summary

Modifier and TypeField and Description
private final HSSFWorkbook
private CellType
private HSSFComment
private CellValueRecordInterface
private final HSSFSheet
private HSSFRichTextString
public static final short
public static final short
public static final short
private static final String
private static final String
public static final int
LAST_COLUMN_NUMBER

The maximum number of columns in BIFF8

Constructor Summary

AccessConstructor and Description
protected
HSSFCell(HSSFWorkbook
- Workbook record of the workbook containing this cell
book
,
HSSFSheet
- Sheet record of the sheet containing this cell
sheet
,
int
- the row of this cell
row
,
short
- the column for this cell
col
)

Creates new Cell - Should only be called by HSSFRow.

protected
HSSFCell(HSSFWorkbook
- Workbook record of the workbook containing this cell
book
,
HSSFSheet
- Sheet record of the sheet containing this cell
sheet
,
int
- the row of this cell
row
,
short
- the column for this cell
col
,
CellType
- Type of cell
type
)

Creates new Cell - Should only be called by HSSFRow.

protected
HSSFCell(HSSFWorkbook
- Workbook record of the workbook containing this cell
book
,
HSSFSheet
- Sheet record of the sheet containing this cell
sheet
,
CellValueRecordInterface
- the Cell Value Record we wish to represent
cval
)

Creates an HSSFCell from a CellValueRecordInterface.

Method Summary

Modifier and TypeMethod and Description
private short

Returns:

the index of a ExtendedFormatRecord record that will be referenced by the cell
applyUserCellStyle
(HSSFCellStyle
the user style to apply
style
)

Applying a user-defined style (UDS) is special.

private static void
checkBounds(int cellIndex)

private static void
private boolean
convertCellValueToBoolean()

Chooses a new boolean value for the cell when its type is changing.

private String
private static CellType
determineType(CellValueRecordInterface cval)

used internally -- given a cell value record, figure out its type

public CellRangeAddress
getArrayFormulaRange()

Implements org.apache.poi.ss.usermodel.Cell.getArrayFormulaRange.

Only valid for array formula cells

public boolean
getBooleanCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getBooleanCellValue.

get the value of the cell as a boolean.

protected InternalWorkbook
getBoundWorkbook()

Returns the Workbook that this Cell is bound to

public CellType

Returns:

one of (CellType#NUMERIC, CellType#STRING, CellType#BOOLEAN, CellType#ERROR) depending on the cached value of the formula
getCachedFormulaResultType
()

Implements org.apache.poi.ss.usermodel.Cell.getCachedFormulaResultType.

Only valid for formula cells

public HSSFComment

Returns:

comment associated with this cell
getCellComment
()

Implements org.apache.poi.ss.usermodel.Cell.getCellComment.

Returns comment associated with this cell

public String
getCellFormula()

Implements org.apache.poi.ss.usermodel.Cell.getCellFormula.

Return a formula for the cell, for example, SUM(C4:E4)

public HSSFCellStyle
getCellStyle()

Implements org.apache.poi.ss.usermodel.Cell.getCellStyle.

get the style for the cell.

public CellType
getCellType()

Implements org.apache.poi.ss.usermodel.Cell.getCellType.

get the cells type (numeric, formula or string)

protected CellValueRecordInterface

Returns:

CellValueRecordInterface representing the cell via the low level api.
getCellValueRecord
()

Should only be used by HSSFSheet and friends.

public int
getColumnIndex()

Implements org.apache.poi.ss.usermodel.Cell.getColumnIndex.

Returns column index of this cell

public Date
getDateCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getDateCellValue.

Get the value of the cell as a date.

public byte
getErrorCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getErrorCellValue.

get the value of the cell as an error code.

public LocalDateTime
getLocalDateTimeCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getLocalDateTimeCellValue.

Get the value of the cell as a LocalDateTime.

public double
getNumericCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getNumericCellValue.

Get the value of the cell as a number.

public HSSFRichTextString
getRichStringCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getRichStringCellValue.

get the value of the cell as a string - for numeric cells we throw an exception.

public HSSFRow

Returns:

the HSSFRow that owns this cell
getRow
()

Implements org.apache.poi.ss.usermodel.Cell.getRow.

Returns the HSSFRow this cell belongs to

public int

Returns:

the (zero based) index of the row containing this cell
getRowIndex
()

Implements org.apache.poi.ss.usermodel.Cell.getRowIndex.

Returns row index of a row in the sheet that contains this cell

public HSSFSheet

Returns:

the HSSFSheet that owns this cell
getSheet
()

Implements org.apache.poi.ss.usermodel.Cell.getSheet.

Returns the HSSFSheet this cell belongs to

protected SpreadsheetVersion
getSpreadsheetVersion()

Implements abstract org.apache.poi.ss.usermodel.CellBase.getSpreadsheetVersion.

Get the spreadsheet version for the given implementation.

public String
getStringCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getStringCellValue.

get the value of the cell as a string - for numeric cells we throw an exception.

public boolean
private void
notifyFormulaChanging()

Should be called any time that a formula could potentially be deleted.

private CellValue
public void
removeCellComment()

Implements org.apache.poi.ss.usermodel.Cell.removeCellComment.

Removes the comment for this cell, if there is one.

protected void
removeFormulaImpl()

Implements abstract org.apache.poi.ss.usermodel.CellBase.removeFormulaImpl.

Implementation-specific removal of the formula.

private void
public void
setAsActiveCell()

Implements org.apache.poi.ss.usermodel.Cell.setAsActiveCell.

Sets this cell as the active cell for the worksheet

pack-priv void
public void
setCellComment(Comment
comment associated with this cell
comment
)

Implements org.apache.poi.ss.usermodel.Cell.setCellComment.

Assign a comment to this cell.

public void
setCellErrorValue(byte
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, see FormulaError.
errorCode
)

Implements org.apache.poi.ss.usermodel.Cell.setCellErrorValue.

Deprecated 3.15 beta 2. Use setCellErrorValue(FormulaError) instead.

set an error value for the cell

public void
setCellErrorValue(FormulaError
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.
error
)

set an error value for the cell

protected void
setCellFormulaImpl(String
The text of the formula to set.
formula
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellFormulaImpl.

Implementation-specific setting the formula.

public void
setCellStyle(CellStyle
reference contained in the workbook
style
)

Implements org.apache.poi.ss.usermodel.Cell.setCellStyle.

Set the style for the cell.

public void
private void
setCellType(CellType cellType, boolean setValue, int row, short col, short styleIndex)

sets the cell type.

protected void
setCellTypeImpl(CellType
new cell type. Guaranteed non-null, not _NONE.
cellType
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellTypeImpl.

Implementation-specific logic

public void
setCellValue(boolean
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.
value
)

Implements org.apache.poi.ss.usermodel.Cell.setCellValue.

set a boolean value for the cell

protected void
setCellValueImpl(double
the new value to set
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a numeric value.

protected void
setCellValueImpl(Date
the new date to set
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a date value.

protected void
setCellValueImpl(LocalDateTime
the new date to set
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a date value.

protected void
setCellValueImpl(Calendar
the new calendar value to set
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a calendar value.

protected void
setCellValueImpl(String
the new value to set.
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a string value.

protected void
setCellValueImpl(RichTextString
the new value to set.
value
)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a RichTextString value.

public String
toString()

Overrides java.lang.Object.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.

private static RuntimeException
typeMismatch(CellType expectedTypeCode, CellType actualTypeCode, boolean isFormulaCell)

protected void
updateCellNum(short
the new cell number
num
)

Updates the cell record's idea of what column it belongs in (0 based)

Inherited from org.apache.poi.ss.usermodel.CellBase:
getAddressgetValueTyperemoveFormulasetBlanksetCellFormulasetCellTypesetCellValuesetCellValuesetCellValuesetCellValuesetCellValuesetCellValuetryToDeleteArrayFormula

Field Detail

_bookback to summary
private final HSSFWorkbook _book
_cellTypeback to summary
private CellType _cellType
_commentback to summary
private HSSFComment _comment
_recordback to summary
private CellValueRecordInterface _record
_sheetback to summary
private final HSSFSheet _sheet
_stringValueback to summary
private HSSFRichTextString _stringValue
ENCODING_COMPRESSED_UNICODEback to summary
public static final short ENCODING_COMPRESSED_UNICODE
ENCODING_UNCHANGEDback to summary
public static final short ENCODING_UNCHANGED
ENCODING_UTF_16back to summary
public static final short ENCODING_UTF_16
FILE_FORMAT_NAMEback to summary
private static final String FILE_FORMAT_NAME
LAST_COLUMN_NAMEback to summary
private static final String LAST_COLUMN_NAME
LAST_COLUMN_NUMBERback to summary
public static final int LAST_COLUMN_NUMBER

The maximum number of columns in BIFF8

Constructor Detail

HSSFCellback to summary
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col)

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:HSSFWorkbook

- Workbook record of the workbook containing this cell

sheet:HSSFSheet

- Sheet record of the sheet containing this cell

row:int

- the row of this cell

col:short

- the column for this cell

See Also
org.apache.poi.hssf.usermodel.HSSFRow#createCell(int)
HSSFCellback to summary
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type)

Creates new Cell - Should only be called by HSSFRow. This creates a cell from scratch.

Parameters
book:HSSFWorkbook

- Workbook record of the workbook containing this cell

sheet:HSSFSheet

- Sheet record of the sheet containing this cell

row:int

- the row of this cell

col:short

- the column for this cell

type:CellType

- Type of cell

See Also
org.apache.poi.hssf.usermodel.HSSFRow#createCell(int, CellType)
HSSFCellback to summary
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval)

Creates an HSSFCell from a CellValueRecordInterface. HSSFSheet uses this when reading in cells from an existing sheet.

Parameters
book:HSSFWorkbook

- Workbook record of the workbook containing this cell

sheet:HSSFSheet

- Sheet record of the sheet containing this cell

cval:CellValueRecordInterface

- the Cell Value Record we wish to represent

Method Detail

applyUserCellStyleback to summary
private short applyUserCellStyle(HSSFCellStyle style)

Applying a user-defined style (UDS) is special. Excel does not directly reference user-defined styles, but instead create a 'proxy' ExtendedFormatRecord referencing the UDS as parent. The proceudre to apply a UDS is as follows: 1. search for a ExtendedFormatRecord with parentIndex == style.getIndex() and xfType == ExtendedFormatRecord.XF_CELL. 2. if not found then create a new ExtendedFormatRecord and copy all attributes from the user-defined style and set the parentIndex to be style.getIndex() 3. return the index of the ExtendedFormatRecord, this will be assigned to the parent cell record

Parameters
style:HSSFCellStyle

the user style to apply

Returns:short

the index of a ExtendedFormatRecord record that will be referenced by the cell

checkBoundsback to summary
private static void checkBounds(int cellIndex)
Exceptions
IllegalStateException:
if the bounds are exceeded.
checkFormulaCachedValueTypeback to summary
private static void checkFormulaCachedValueType(CellType expectedTypeCode, FormulaRecord fr)
convertCellValueToBooleanback to summary
private boolean convertCellValueToBoolean()

Chooses a new boolean value for the cell when its type is changing.

Usually the caller is calling setCellType() with the intention of calling setCellValue(boolean) straight afterwards. This method only exists to give the cell a somewhat reasonable value until the setCellValue() call (if at all). TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this

Exceptions
IllegalStateException:
if cell type cannot be converted to boolean
convertCellValueToStringback to summary
private String convertCellValueToString()
determineTypeback to summary
private static CellType determineType(CellValueRecordInterface cval)

used internally -- given a cell value record, figure out its type

getArrayFormulaRangeback to summary
public CellRangeAddress getArrayFormulaRange()

Implements org.apache.poi.ss.usermodel.Cell.getArrayFormulaRange.

Doc from org.apache.poi.ss.usermodel.Cell.getArrayFormulaRange.

Only valid for array formula cells

Returns:CellRangeAddress

range of the array formula group that the cell belongs to.

Annotations
@Override
getBooleanCellValueback to summary
public boolean getBooleanCellValue()

Implements org.apache.poi.ss.usermodel.Cell.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:boolean

Doc from org.apache.poi.ss.usermodel.Cell.getBooleanCellValue.

the value of the cell as a boolean

Annotations
@Override
getBoundWorkbookback to summary
protected InternalWorkbook getBoundWorkbook()

Returns the Workbook that this Cell is bound to

getCachedFormulaResultTypeback to summary
public CellType getCachedFormulaResultType()

Implements org.apache.poi.ss.usermodel.Cell.getCachedFormulaResultType.

Only valid for formula cells

Returns:CellType

one of (CellType#NUMERIC, CellType#STRING, CellType#BOOLEAN, CellType#ERROR) depending on the cached value of the formula

Annotations
@Override
Since
POI 4.0
getCellCommentback to summary
public HSSFComment getCellComment()

Implements org.apache.poi.ss.usermodel.Cell.getCellComment.

Returns comment associated with this cell

Returns:HSSFComment

comment associated with this cell

Annotations
@Override
getCellFormulaback to summary
public String getCellFormula()

Implements org.apache.poi.ss.usermodel.Cell.getCellFormula.

Doc from org.apache.poi.ss.usermodel.Cell.getCellFormula.

Return a formula for the cell, for example, SUM(C4:E4)

Returns:String

a formula for the cell

Annotations
@Override
getCellStyleback to summary
public HSSFCellStyle getCellStyle()

Implements org.apache.poi.ss.usermodel.Cell.getCellStyle.

get the style for the cell. This is a reference to a cell style contained in the workbook object.

Returns:HSSFCellStyle

Doc from org.apache.poi.ss.usermodel.Cell.getCellStyle.

the cell's style. Always not-null. Default cell style has zero index and can be obtained as workbook.getCellStyleAt(0)

Annotations
@Override
See Also
org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(int)
getCellTypeback to summary
public CellType getCellType()

Implements org.apache.poi.ss.usermodel.Cell.getCellType.

get the cells type (numeric, formula or string)

Returns:CellType

Doc from org.apache.poi.ss.usermodel.Cell.getCellType.

the cell type

Annotations
@Override
getCellValueRecordback to summary
protected CellValueRecordInterface getCellValueRecord()

Should only be used by HSSFSheet and friends. Returns the low level CellValueRecordInterface record

Returns:CellValueRecordInterface

CellValueRecordInterface representing the cell via the low level api.

getColumnIndexback to summary
public int getColumnIndex()

Implements org.apache.poi.ss.usermodel.Cell.getColumnIndex.

Doc from org.apache.poi.ss.usermodel.Cell.getColumnIndex.

Returns column index of this cell

Returns:int

zero-based column index of a column in a sheet.

Annotations
@Override
getDateCellValueback to summary
public Date getDateCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getDateCellValue.

Get the value of the cell as a date. For strings we throw an exception. For blank cells we return a null. See HSSFDataFormatter for formatting this date into a string similar to how excel does.

Returns:Date

Doc from org.apache.poi.ss.usermodel.Cell.getDateCellValue.

the value of the cell as a date

Annotations
@Override
getErrorCellValueback to summary
public byte getErrorCellValue()

Implements org.apache.poi.ss.usermodel.Cell.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:byte

Doc from org.apache.poi.ss.usermodel.Cell.getErrorCellValue.

the value of the cell as an error code

Annotations
@Override
getLocalDateTimeCellValueback to summary
public LocalDateTime getLocalDateTimeCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getLocalDateTimeCellValue.

Get the value of the cell as a LocalDateTime. For strings we throw an exception. For blank cells we return a null. See HSSFDataFormatter for formatting this date into a string similar to how excel does.

Returns:LocalDateTime

Doc from org.apache.poi.ss.usermodel.Cell.getLocalDateTimeCellValue.

the value of the cell as a LocalDateTime

Annotations
@Override
getNumericCellValueback to summary
public double getNumericCellValue()

Implements org.apache.poi.ss.usermodel.Cell.getNumericCellValue.

Get the value of the cell as a number. For strings we throw an exception. For blank cells we return a 0. See HSSFDataFormatter for turning this number into a string similar to that which Excel would render this number as.

Returns:double

Doc from org.apache.poi.ss.usermodel.Cell.getNumericCellValue.

the value of the cell as a number

Annotations
@Override
getRichStringCellValueback to summary
public HSSFRichTextString getRichStringCellValue()

Implements org.apache.poi.ss.usermodel.Cell.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:HSSFRichTextString

Doc from org.apache.poi.ss.usermodel.Cell.getRichStringCellValue.

the value of the cell as a XSSFRichTextString

Annotations
@Override
getRowback to summary
public HSSFRow getRow()

Implements org.apache.poi.ss.usermodel.Cell.getRow.

Returns the HSSFRow this cell belongs to

Returns:HSSFRow

the HSSFRow that owns this cell

Annotations
@Override
getRowIndexback to summary
public int getRowIndex()

Implements org.apache.poi.ss.usermodel.Cell.getRowIndex.

Doc from org.apache.poi.ss.usermodel.Cell.getRowIndex.

Returns row index of a row in the sheet that contains this cell

Returns:int

the (zero based) index of the row containing this cell

Annotations
@Override
getSheetback to summary
public HSSFSheet getSheet()

Implements org.apache.poi.ss.usermodel.Cell.getSheet.

Returns the HSSFSheet this cell belongs to

Returns:HSSFSheet

the HSSFSheet that owns this cell

Annotations
@Override
getSpreadsheetVersionback to summary
protected SpreadsheetVersion getSpreadsheetVersion()

Implements abstract org.apache.poi.ss.usermodel.CellBase.getSpreadsheetVersion.

Doc from org.apache.poi.ss.usermodel.CellBase.getSpreadsheetVersion.

Get the spreadsheet version for the given implementation.

Returns:SpreadsheetVersion

the spreadsheet version

Annotations
@Override
getStringCellValueback to summary
public String getStringCellValue()

Implements org.apache.poi.ss.usermodel.Cell.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:String

Doc from org.apache.poi.ss.usermodel.Cell.getStringCellValue.

the value of the cell as a string

Annotations
@Override
isPartOfArrayFormulaGroupback to summary
public boolean isPartOfArrayFormulaGroup()

Implements org.apache.poi.ss.usermodel.Cell.isPartOfArrayFormulaGroup.

Returns:boolean

Doc from org.apache.poi.ss.usermodel.Cell.isPartOfArrayFormulaGroup.

true if this cell is part of group of cells having a common array formula.

Annotations
@Override
notifyFormulaChangingback to summary
private void notifyFormulaChanging()

Should be called any time that a formula could potentially be deleted. Does nothing if this cell currently does not hold a formula

readValueback to summary
private CellValue readValue()
removeCellCommentback to summary
public void removeCellComment()

Implements org.apache.poi.ss.usermodel.Cell.removeCellComment.

Removes the comment for this cell, if there is one. WARNING - some versions of excel will loose all comments after performing this action!

Annotations
@Override
removeFormulaImplback to summary
protected void removeFormulaImpl()

Implements abstract org.apache.poi.ss.usermodel.CellBase.removeFormulaImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.removeFormulaImpl.

Implementation-specific removal of the formula. The cell is guaranteed to have a regular formula set. Shall preserve the "cached" value.

Annotations
@Override
restoreValueback to summary
private void restoreValue(CellValue value)
setAsActiveCellback to summary
public void setAsActiveCell()

Implements org.apache.poi.ss.usermodel.Cell.setAsActiveCell.

Doc from org.apache.poi.ss.usermodel.Cell.setAsActiveCell.

Sets this cell as the active cell for the worksheet

Annotations
@Override
setCellArrayFormulaback to summary
pack-priv void setCellArrayFormula(CellRangeAddress range)
setCellCommentback to summary
public void setCellComment(Comment comment)

Implements org.apache.poi.ss.usermodel.Cell.setCellComment.

Assign a comment to this cell. If the supplied comment is null, the comment for this cell will be removed.

Parameters
comment:Comment

comment associated with this cell

Annotations
@Override
setCellErrorValueback to summary
public void setCellErrorValue(byte errorCode)

Implements org.apache.poi.ss.usermodel.Cell.setCellErrorValue.

Deprecated

3.15 beta 2. Use setCellErrorValue(FormulaError) instead.

set an error value for the cell

Parameters
errorCode:byte

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, see FormulaError.

Annotations
@Override
@Deprecated
setCellErrorValueback to summary
public void setCellErrorValue(FormulaError error)

set an error value for the cell

Parameters
error:FormulaError

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.

Annotations
@SuppressWarnings:fallthrough
setCellFormulaImplback to summary
protected void setCellFormulaImpl(String formula)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellFormulaImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellFormulaImpl.

Implementation-specific setting the formula. Formula is not null. Shall not change the value.

Parameters
formula:String

The text of the formula to set.

Annotations
@Override
setCellStyleback to summary
public void setCellStyle(CellStyle style)

Implements org.apache.poi.ss.usermodel.Cell.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 org.apache.poi.ss.util.CellUtil#setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, java.util.Map)

Parameters
style:CellStyle

reference contained in the workbook

Annotations
@Override
See Also
org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle(), org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(int)
setCellStyleback to summary
public void setCellStyle(HSSFCellStyle style)
setCellTypeback to summary
private void setCellType(CellType cellType, boolean setValue, int row, short col, short styleIndex)

sets the cell type. The setValue flag indicates whether to bother about trying to preserve the current value in the new record if one is created.

The @see #setCellValue method will call this method with false in setValue since it will overwrite the cell value later

setCellTypeImplback to summary
protected void setCellTypeImpl(CellType cellType)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellTypeImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellTypeImpl.

Implementation-specific logic

Parameters
cellType:CellType

new cell type. Guaranteed non-null, not _NONE.

Annotations
@Override
setCellValueback to summary
public void setCellValue(boolean value)

Implements org.apache.poi.ss.usermodel.Cell.setCellValue.

set a boolean value for the cell

Parameters
value:boolean

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.

Annotations
@Override
@SuppressWarnings:fallthrough
setCellValueImplback to summary
protected void setCellValueImpl(double value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a numeric value. value is 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 return CellType#NUMERIC.

Parameters
value:double

the new value to set

Annotations
@Override
@SuppressWarnings:fallthrough
setCellValueImplback to summary
protected void setCellValueImpl(Date value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a date value. value is guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would return CellType#NUMERIC.

In HSSF, only the number of days is stored. The fractional part is ignored.

Parameters
value:Date

the new date to set

Annotations
@Override
See Also
DateUtil, org.apache.poi.ss.usermodel.DateUtil
setCellValueImplback to summary
protected void setCellValueImpl(LocalDateTime value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a date value. value is guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would return CellType#NUMERIC.

In HSSF, only the number of days is stored. The fractional part is ignored.

Parameters
value:LocalDateTime

the new date to set

Annotations
@Override
See Also
DateUtil, org.apache.poi.ss.usermodel.DateUtil
setCellValueImplback to summary
protected void setCellValueImpl(Calendar value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-specific way to set a calendar value. value is guaranteed to be non-null. The implementation is expected to adjust the cell type accordingly, so that after this call getCellType() or getCachedFormulaResultType() would return CellType#NUMERIC.

Parameters
value:Calendar

the new calendar value to set

Annotations
@Override
setCellValueImplback to summary
protected void setCellValueImpl(String value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-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 return CellType#STRING.

Parameters
value:String

the new value to set.

Annotations
@Override
setCellValueImplback to summary
protected void setCellValueImpl(RichTextString value)

Implements abstract org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Doc from org.apache.poi.ss.usermodel.CellBase.setCellValueImpl.

Implementation-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 return CellType#STRING.

Parameters
value:RichTextString

the new value to set.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.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>

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

typeMismatchback to summary
private static RuntimeException typeMismatch(CellType expectedTypeCode, CellType actualTypeCode, boolean isFormulaCell)
updateCellNumback to summary
protected void updateCellNum(short num)

Updates the cell record's idea of what column it belongs in (0 based)

Parameters
num:short

the new cell number