public class HSSFCell extends CellBase
Cells should have their number (0 based) before being added to a row. Only cells that have values should be added.
Modifier and Type | Field and Description |
---|---|
static short |
ENCODING_COMPRESSED_UNICODE |
static short |
ENCODING_UNCHANGED |
static short |
ENCODING_UTF_16 |
static int |
LAST_COLUMN_NUMBER
The maximum number of columns in BIFF8
|
Modifier | Constructor and Description |
---|---|
protected |
HSSFCell(HSSFWorkbook book,
HSSFSheet sheet,
CellValueRecordInterface cval)
Creates an HSSFCell from a CellValueRecordInterface.
|
protected |
HSSFCell(HSSFWorkbook book,
HSSFSheet sheet,
int row,
short col)
Creates new Cell - Should only be called by HSSFRow.
|
protected |
HSSFCell(HSSFWorkbook book,
HSSFSheet sheet,
int row,
short col,
CellType type)
Creates new Cell - Should only be called by HSSFRow.
|
Modifier and Type | Method and Description |
---|---|
CellRangeAddress |
getArrayFormulaRange()
Only valid for array formula cells
|
boolean |
getBooleanCellValue()
get the value of the cell as a boolean.
|
protected InternalWorkbook |
getBoundWorkbook()
Returns the Workbook that this Cell is bound to
|
CellType |
getCachedFormulaResultType()
Only valid for formula cells
|
CellType |
getCachedFormulaResultTypeEnum()
Deprecated.
use
getCachedFormulaResultType
Will be deleted when we make the CellType enum transition. See bug 59791. |
HSSFComment |
getCellComment()
Returns comment associated with this cell
|
java.lang.String |
getCellFormula()
Return a formula for the cell, for example,
SUM(C4:E4) |
HSSFCellStyle |
getCellStyle()
get the style for the cell.
|
CellType |
getCellType()
get the cells type (numeric, formula or string)
|
protected CellValueRecordInterface |
getCellValueRecord()
Should only be used by HSSFSheet and friends.
|
int |
getColumnIndex()
Returns column index of this cell
|
java.util.Date |
getDateCellValue()
Get the value of the cell as a date.
|
byte |
getErrorCellValue()
get the value of the cell as an error code.
|
HSSFHyperlink |
getHyperlink() |
java.time.LocalDateTime |
getLocalDateTimeCellValue()
Get the value of the cell as a LocalDateTime.
|
double |
getNumericCellValue()
Get the value of the cell as a number.
|
HSSFRichTextString |
getRichStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception.
|
HSSFRow |
getRow()
Returns the HSSFRow this cell belongs to
|
int |
getRowIndex()
Returns row index of a row in the sheet that contains this cell
|
HSSFSheet |
getSheet()
Returns the HSSFSheet this cell belongs to
|
protected SpreadsheetVersion |
getSpreadsheetVersion()
Get the spreadsheet version for the given implementation.
|
java.lang.String |
getStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception.
|
boolean |
isPartOfArrayFormulaGroup() |
void |
removeCellComment()
Removes the comment for this cell, if
there is one.
|
protected void |
removeFormulaImpl()
Implementation-specific removal of the formula.
|
void |
removeHyperlink()
Removes the hyperlink for this cell, if there is one.
|
void |
setAsActiveCell()
Sets this cell as the active cell for the worksheet
|
void |
setCellComment(Comment comment)
Assign a comment to this cell.
|
void |
setCellErrorValue(byte errorCode)
Deprecated.
3.15 beta 2. Use
setCellErrorValue(FormulaError) instead. |
void |
setCellErrorValue(FormulaError error)
set a error value for the cell
|
protected void |
setCellFormulaImpl(java.lang.String formula)
Implementation-specific setting the formula.
|
void |
setCellStyle(CellStyle style)
Set the style for the cell.
|
void |
setCellStyle(HSSFCellStyle style) |
protected void |
setCellTypeImpl(CellType cellType)
Implementation-specific logic
|
void |
setCellValue(boolean value)
set a boolean value for the cell
|
protected void |
setCellValueImpl(java.util.Calendar value)
Implementation-specific way to set a calendar value.
|
protected void |
setCellValueImpl(java.util.Date value)
Implementation-specific way to set a date value.
|
protected void |
setCellValueImpl(double value)
Implementation-specific way to set a numeric value.
|
protected void |
setCellValueImpl(java.time.LocalDateTime value)
Implementation-specific way to set a date value.
|
protected void |
setCellValueImpl(RichTextString value)
Implementation-specific way to set a RichTextString value.
|
protected void |
setCellValueImpl(java.lang.String value)
Implementation-specific way to set a string value.
|
void |
setHyperlink(Hyperlink hyperlink)
Assign a hyperlink to this cell.
|
java.lang.String |
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 void |
updateCellNum(short num)
Updates the cell record's idea of what
column it belongs in (0 based)
|
getAddress, getCellTypeEnum, getValueType, removeFormula, setBlank, setCellFormula, setCellType, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, tryToDeleteArrayFormula
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setCellValue
public static final int LAST_COLUMN_NUMBER
public static final short ENCODING_UNCHANGED
public static final short ENCODING_COMPRESSED_UNICODE
public static final short ENCODING_UTF_16
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col)
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.
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 cellHSSFRow.createCell(int)
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type)
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 cellHSSFRow.createCell(int,CellType)
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval)
book
- - Workbook record of the workbook containing this cellsheet
- - Sheet record of the sheet containing this cellcval
- - the Cell Value Record we wish to representprotected SpreadsheetVersion getSpreadsheetVersion()
getSpreadsheetVersion
in class CellBase
public HSSFSheet getSheet()
public HSSFRow getRow()
protected InternalWorkbook getBoundWorkbook()
public int getRowIndex()
Cell
protected void updateCellNum(short num)
num
- the new cell numberpublic int getColumnIndex()
Cell
protected void setCellTypeImpl(CellType cellType)
CellBase
setCellTypeImpl
in class CellBase
cellType
- new cell type. Guaranteed non-null, not _NONE.public CellType getCellType()
protected void setCellValueImpl(double 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
.setCellValueImpl
in class CellBase
value
- the new value to setprotected void setCellValueImpl(java.util.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.
setCellValueImpl
in class CellBase
value
- the new date to setDateUtil
,
DateUtil
protected void setCellValueImpl(java.time.LocalDateTime 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.
setCellValueImpl
in class CellBase
value
- the new date to setDateUtil
,
DateUtil
protected void setCellValueImpl(java.util.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
.setCellValueImpl
in class CellBase
value
- the new calendar value to setprotected void setCellValueImpl(java.lang.String value)
CellType.STRING
.setCellValueImpl
in class CellBase
value
- the new value to set.protected void setCellValueImpl(RichTextString value)
CellType.STRING
.setCellValueImpl
in class CellBase
value
- the new value to set.protected void setCellFormulaImpl(java.lang.String formula)
setCellFormulaImpl
in class CellBase
protected void removeFormulaImpl()
CellBase
removeFormulaImpl
in class CellBase
public java.lang.String getCellFormula()
Cell
SUM(C4:E4)
public double getNumericCellValue()
HSSFDataFormatter
for turning this
number into a string similar to that which
Excel would render this number as.for turning this number into a string similar to that which Excel would render this number as.
public java.util.Date getDateCellValue()
HSSFDataFormatter
for formatting
this date into a string similar to how excel does.for formatting this date into a string similar to how excel does.
public java.time.LocalDateTime getLocalDateTimeCellValue()
HSSFDataFormatter
for formatting
this date into a string similar to how excel does.for formatting this date into a string similar to how excel does.
public java.lang.String getStringCellValue()
public HSSFRichTextString getRichStringCellValue()
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 void setCellErrorValue(byte errorCode)
setCellErrorValue(FormulaError)
instead.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, see FormulaError
.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 boolean getBooleanCellValue()
public byte getErrorCellValue()
for error codes
public void setCellStyle(CellStyle style)
Set the style for the cell. The style should be an HSSFCellStyle created/retreived from the HSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style,
use CellUtil.setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, java.util.Map)
style
- reference contained in the workbookHSSFWorkbook.createCellStyle()
,
HSSFWorkbook.getCellStyleAt(int)
public void setCellStyle(HSSFCellStyle style)
public HSSFCellStyle getCellStyle()
workbook.getCellStyleAt(0)
HSSFWorkbook.getCellStyleAt(int)
protected CellValueRecordInterface getCellValueRecord()
public void setAsActiveCell()
public java.lang.String toString()
toString
in class java.lang.Object
public void setCellComment(Comment comment)
comment
- comment associated with this cellpublic HSSFComment getCellComment()
public void removeCellComment()
public HSSFHyperlink getHyperlink()
null
if not foundpublic void setHyperlink(Hyperlink hyperlink)
hyperlink
- hyperlink associated with this cellpublic void removeHyperlink()
public CellType getCachedFormulaResultType()
CellType.NUMERIC
, CellType.STRING
,
CellType.BOOLEAN
, CellType.ERROR
) depending
on the cached value of the formula@Deprecated @Removal(version="4.2") public CellType getCachedFormulaResultTypeEnum()
getCachedFormulaResultType
Will be deleted when we make the CellType enum transition. See bug 59791.CellType.NUMERIC
, CellType.STRING
,
CellType.BOOLEAN
, CellType.ERROR
) depending
on the cached value of the formulapublic CellRangeAddress getArrayFormulaRange()
Cell
public boolean isPartOfArrayFormulaGroup()
true
if this cell is part of group of cells having a common array formula.Copyright 2020 The Apache Software Foundation or its licensors, as applicable.