|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Cell
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 conatin 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.
Field Summary | |
---|---|
static int |
CELL_TYPE_BLANK
Blank Cell type (3) |
static int |
CELL_TYPE_BOOLEAN
Boolean Cell type (4) |
static int |
CELL_TYPE_ERROR
Error Cell type (5) |
static int |
CELL_TYPE_FORMULA
Formula Cell type (2) |
static int |
CELL_TYPE_NUMERIC
Numeric Cell type (0) |
static int |
CELL_TYPE_STRING
String Cell type (1) |
Method Summary | |
---|---|
CellRangeAddress |
getArrayFormulaRange()
Only valid for array formula cells |
boolean |
getBooleanCellValue()
Get the value of the cell as a boolean. |
int |
getCachedFormulaResultType()
Only valid for formula cells |
Comment |
getCellComment()
Returns comment associated with this cell |
java.lang.String |
getCellFormula()
Return a formula for the cell, for example, SUM(C4:E4) |
CellStyle |
getCellStyle()
Return the cell's style. |
int |
getCellType()
Return the cell type. |
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. |
Hyperlink |
getHyperlink()
|
double |
getNumericCellValue()
Get the value of the cell as a number. |
RichTextString |
getRichStringCellValue()
Get the value of the cell as a XSSFRichTextString |
Row |
getRow()
Returns the Row this cell belongs to |
int |
getRowIndex()
Returns row index of a row in the sheet that contains this cell |
Sheet |
getSheet()
Returns the sheet this cell belongs to |
java.lang.String |
getStringCellValue()
Get the value of the cell as a string |
boolean |
isPartOfArrayFormulaGroup()
|
void |
removeCellComment()
Removes the comment for this cell, if there is one. |
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 value)
Set a error value for the cell |
void |
setCellFormula(java.lang.String formula)
Sets formula for this cell. |
void |
setCellStyle(CellStyle style)
Set the style for the cell. |
void |
setCellType(int cellType)
Set the cells type (numeric, formula or string). |
void |
setCellValue(boolean value)
Set a boolean value for the cell |
void |
setCellValue(java.util.Calendar value)
Set a date value for the cell. |
void |
setCellValue(java.util.Date value)
Converts the supplied date to its equivalent Excel numeric value and sets that into the cell. |
void |
setCellValue(double value)
Set a numeric value for the cell |
void |
setCellValue(RichTextString value)
Set a rich string value for the cell. |
void |
setCellValue(java.lang.String value)
Set a string value for the cell. |
void |
setHyperlink(Hyperlink link)
Assign a hyperlink to this cell |
Field Detail |
---|
static final int CELL_TYPE_NUMERIC
setCellType(int)
,
getCellType()
,
Constant Field Valuesstatic final int CELL_TYPE_STRING
setCellType(int)
,
getCellType()
,
Constant Field Valuesstatic final int CELL_TYPE_FORMULA
setCellType(int)
,
getCellType()
,
Constant Field Valuesstatic final int CELL_TYPE_BLANK
setCellType(int)
,
getCellType()
,
Constant Field Valuesstatic final int CELL_TYPE_BOOLEAN
setCellType(int)
,
getCellType()
,
Constant Field Valuesstatic final int CELL_TYPE_ERROR
setCellType(int)
,
getCellType()
,
Constant Field ValuesMethod Detail |
---|
int getColumnIndex()
int getRowIndex()
Sheet getSheet()
Row getRow()
void setCellType(int cellType)
If the cell currently contains a value, the value will be converted to match the new type, if possible. Formatting is generally lost in the process however.
If what you want to do is get a String value for your
numeric cell, stop!. This is not the way to do it.
Instead, for fetching the string value of a numeric or boolean
or date cell, use DataFormatter
instead.
java.lang.IllegalArgumentException
- if the specified cell type is invalid
java.lang.IllegalStateException
- if the current value cannot be converted to the new typeCELL_TYPE_NUMERIC
,
CELL_TYPE_STRING
,
CELL_TYPE_FORMULA
,
CELL_TYPE_BLANK
,
CELL_TYPE_BOOLEAN
,
CELL_TYPE_ERROR
int getCellType()
CELL_TYPE_BLANK
,
CELL_TYPE_NUMERIC
,
CELL_TYPE_STRING
,
CELL_TYPE_FORMULA
,
CELL_TYPE_BOOLEAN
,
CELL_TYPE_ERROR
int getCachedFormulaResultType()
CELL_TYPE_NUMERIC
, CELL_TYPE_STRING
,
CELL_TYPE_BOOLEAN
, CELL_TYPE_ERROR
) depending
on the cached value of the formulavoid setCellValue(double value)
value
- the numeric value to set this cell to. For formulas we'll set the
precalculated value, for numerics we'll set its value. For other types we
will change the cell to a numeric cell and set its value.void setCellValue(java.util.Date value)
CELL_TYPE_NUMERIC
. POI
does not attempt to replicate this behaviour. To make a numeric cell
display as a date, use setCellStyle(CellStyle)
etc.
value
- the numeric value to set this cell to. For formulas we'll set the
precalculated value, for numerics we'll set its value. For other types we
will change the cell to a numerics cell and set its value.void setCellValue(java.util.Calendar value)
This will set the cell value based on the Calendar's timezone. As Excel
does not support timezones this means that both 20:00+03:00 and
20:00-03:00 will be reported as the same value (20:00) even that there
are 6 hours difference between the two times. This difference can be
preserved by using setCellValue(value.getTime())
which will
automatically shift the times to the default timezone.
value
- the date value to set this cell to. For formulas we'll set the
precalculated value, for numerics we'll set its value. For othertypes we
will change the cell to a numeric cell and set its value.void setCellValue(RichTextString value)
value
- value to set the cell to. For formulas we'll set the formula
string, for String cells we'll set its value. For other types we will
change the cell to a string cell and set its value.
If value is null then we will change the cell to a Blank cell.void setCellValue(java.lang.String value)
value
- value to set the cell to. For formulas we'll set the formula
string, for String cells we'll set its value. For other types we will
change the cell to a string cell and set its value.
If value is null then we will change the cell to a Blank cell.void setCellFormula(java.lang.String formula) throws FormulaParseException
Note, this method only sets the formula string and does not calculate the formula value.
To set the precalculated value use setCellValue(double)
or setCellValue(String)
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 invalidjava.lang.String getCellFormula()
SUM(C4:E4)
java.lang.IllegalStateException
- if the cell type returned by getCellType()
is not CELL_TYPE_FORMULAdouble getNumericCellValue()
For strings we throw an exception. For blank cells we return a 0. For formulas or error cells we return the precalculated value;
java.lang.IllegalStateException
- if the cell type returned by getCellType()
is CELL_TYPE_STRING
java.lang.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.
java.util.Date getDateCellValue()
For strings we throw an exception. For blank cells we return a null.
java.lang.IllegalStateException
- if the cell type returned by getCellType()
is CELL_TYPE_STRING
java.lang.NumberFormatException
- if the cell value isn't a parsable double
.for formatting this date into a string similar to how excel does.
RichTextString 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.
java.lang.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.
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.void setCellErrorValue(byte value)
value
- 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
boolean getBooleanCellValue()
For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
java.lang.IllegalStateException
- if the cell type returned by getCellType()
is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULAbyte getErrorCellValue()
For strings, numbers, and booleans, we throw an exception. For blank cells we return a 0.
java.lang.IllegalStateException
- if the cell type returned by getCellType()
isn't CELL_TYPE_ERRORfor error codes
void setCellStyle(CellStyle style)
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.Workbook.createCellStyle()
CellStyle getCellStyle()
workbook.getCellStyleAt(0)
Workbook.getCellStyleAt(short)
void setAsActiveCell()
void setCellComment(Comment comment)
comment
- comment associated with this cellComment getCellComment()
null
if not foundvoid removeCellComment()
Hyperlink getHyperlink()
null
if not foundvoid setHyperlink(Hyperlink link)
link
- hyperlink associated with this cellvoid removeHyperlink()
CellRangeAddress getArrayFormulaRange()
boolean isPartOfArrayFormulaGroup()
true
if this cell is part of group of cells having a common array formula.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |