Interface Cell
-
public interface CellHigh 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
Fields Modifier and Type Field and Description static intCELL_TYPE_BLANKBlank Cell type (3)static intCELL_TYPE_BOOLEANBoolean Cell type (4)static intCELL_TYPE_ERRORError Cell type (5)static intCELL_TYPE_FORMULAFormula Cell type (2)static intCELL_TYPE_NUMERICNumeric Cell type (0)static intCELL_TYPE_STRINGString Cell type (1)
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description CellRangeAddressgetArrayFormulaRange()Only valid for array formula cellsbooleangetBooleanCellValue()Get the value of the cell as a boolean.intgetCachedFormulaResultType()Only valid for formula cellsCommentgetCellComment()Returns comment associated with this celljava.lang.StringgetCellFormula()Return a formula for the cell, for example,SUM(C4:E4)CellStylegetCellStyle()Return the cell's style.intgetCellType()Return the cell type.intgetColumnIndex()Returns column index of this celljava.util.DategetDateCellValue()Get the value of the cell as a date.bytegetErrorCellValue()Get the value of the cell as an error code.HyperlinkgetHyperlink()doublegetNumericCellValue()Get the value of the cell as a number.RichTextStringgetRichStringCellValue()Get the value of the cell as a XSSFRichTextStringRowgetRow()Returns the Row this cell belongs tointgetRowIndex()Returns row index of a row in the sheet that contains this cellSheetgetSheet()Returns the sheet this cell belongs tojava.lang.StringgetStringCellValue()Get the value of the cell as a stringbooleanisPartOfArrayFormulaGroup()voidremoveCellComment()Removes the comment for this cell, if there is one.voidremoveHyperlink()Removes the hyperlink for this cell, if there is one.voidsetAsActiveCell()Sets this cell as the active cell for the worksheetvoidsetCellComment(Comment comment)Assign a comment to this cellvoidsetCellErrorValue(byte value)Set a error value for the cellvoidsetCellFormula(java.lang.String formula)Sets formula for this cell.voidsetCellStyle(CellStyle style)Set the style for the cell.voidsetCellType(int cellType)Set the cells type (numeric, formula or string).voidsetCellValue(boolean value)Set a boolean value for the cellvoidsetCellValue(java.util.Calendar value)Set a date value for the cell.voidsetCellValue(java.util.Date value)Converts the supplied date to its equivalent Excel numeric value and sets that into the cell.voidsetCellValue(double value)Set a numeric value for the cellvoidsetCellValue(RichTextString value)Set a rich string value for the cell.voidsetCellValue(java.lang.String value)Set a string value for the cell.voidsetHyperlink(Hyperlink link)Assign a hyperlink to this cell
-
-
-
Field Detail
-
CELL_TYPE_NUMERIC
static final int CELL_TYPE_NUMERIC
Numeric Cell type (0)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
CELL_TYPE_STRING
static final int CELL_TYPE_STRING
String Cell type (1)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
CELL_TYPE_FORMULA
static final int CELL_TYPE_FORMULA
Formula Cell type (2)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
CELL_TYPE_BLANK
static final int CELL_TYPE_BLANK
Blank Cell type (3)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
CELL_TYPE_BOOLEAN
static final int CELL_TYPE_BOOLEAN
Boolean Cell type (4)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
CELL_TYPE_ERROR
static final int CELL_TYPE_ERROR
Error Cell type (5)- See Also:
setCellType(int),getCellType(), Constant Field Values
-
-
Method Detail
-
getColumnIndex
int getColumnIndex()
Returns column index of this cell- Returns:
- zero-based column index of a column in a sheet.
-
getRowIndex
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
-
getSheet
Sheet getSheet()
Returns the sheet this cell belongs to- Returns:
- the sheet this cell belongs to
-
getRow
Row getRow()
Returns the Row this cell belongs to- Returns:
- the Row that owns this cell
-
setCellType
void setCellType(int cellType)
Set the cells type (numeric, formula or string).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
DataFormatterinstead.- Throws:
java.lang.IllegalArgumentException- if the specified cell type is invalidjava.lang.IllegalStateException- if the current value cannot be converted to the new type- See Also:
CELL_TYPE_NUMERIC,CELL_TYPE_STRING,CELL_TYPE_FORMULA,CELL_TYPE_BLANK,CELL_TYPE_BOOLEAN,CELL_TYPE_ERROR
-
getCellType
int getCellType()
Return the cell type.- Returns:
- the cell type
- See Also:
CELL_TYPE_BLANK,CELL_TYPE_NUMERIC,CELL_TYPE_STRING,CELL_TYPE_FORMULA,CELL_TYPE_BOOLEAN,CELL_TYPE_ERROR
-
getCachedFormulaResultType
int getCachedFormulaResultType()
Only valid for formula cells- Returns:
- one of (
CELL_TYPE_NUMERIC,CELL_TYPE_STRING,CELL_TYPE_BOOLEAN,CELL_TYPE_ERROR) depending on the cached value of the formula
-
setCellValue
void setCellValue(double value)
Set a numeric value for the cell- Parameters:
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.
-
setCellValue
void setCellValue(java.util.Date value)
Converts the supplied date to its equivalent Excel numeric value and sets that into the cell. Note - There is actually no 'DATE' cell type in Excel. In many cases (when entering date values), Excel automatically adjusts the cell style to some date format, creating the illusion that the cell data type is now something besidesCELL_TYPE_NUMERIC. POI does not attempt to replicate this behaviour. To make a numeric cell display as a date, usesetCellStyle(CellStyle)etc.- Parameters:
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.
-
setCellValue
void setCellValue(java.util.Calendar value)
Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as a date.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.- Parameters:
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.
-
setCellValue
void setCellValue(RichTextString value)
Set a rich string value for the cell.- Parameters:
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.
-
setCellValue
void setCellValue(java.lang.String value)
Set a string value for the cell.- Parameters:
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.
-
setCellFormula
void setCellFormula(java.lang.String formula) throws FormulaParseExceptionSets 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
setCellValue(double)orsetCellValue(String)- 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 invalid
-
getCellFormula
java.lang.String getCellFormula()
Return a formula for the cell, for example,SUM(C4:E4)- Returns:
- a formula for the cell
- Throws:
java.lang.IllegalStateException- if the cell type returned bygetCellType()is not CELL_TYPE_FORMULA
-
getNumericCellValue
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:
java.lang.IllegalStateException- if the cell type returned bygetCellType()is CELL_TYPE_STRINGjava.lang.NumberFormatException- if the cell value isn't a parsabledouble.- See Also:
for turning this number into a string similar to that which Excel would render this number as.
-
getDateCellValue
java.util.Date 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:
java.lang.IllegalStateException- if the cell type returned bygetCellType()is CELL_TYPE_STRINGjava.lang.NumberFormatException- if the cell value isn't a parsabledouble.- See Also:
for formatting this date into a string similar to how excel does.
-
getRichStringCellValue
RichTextString 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
-
getStringCellValue
java.lang.String 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
-
setCellValue
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
void setCellErrorValue(byte value)
Set a error value for the cell- Parameters:
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.- See Also:
FormulaError
-
getBooleanCellValue
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:
java.lang.IllegalStateException- if the cell type returned bygetCellType()is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA
-
getErrorCellValue
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
- Throws:
java.lang.IllegalStateException- if the cell type returned bygetCellType()isn't CELL_TYPE_ERROR- See Also:
for error codes
-
setCellStyle
void setCellStyle(CellStyle style)
Set the style for the cell. The style should be an CellStyle created/retreived from the Workbook.- Parameters:
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.- See Also:
Workbook.createCellStyle()
-
getCellStyle
CellStyle getCellStyle()
Return the cell's style.- Returns:
- the cell's style. Always not-null. Default cell style has zero index and can be obtained as
workbook.getCellStyleAt(0) - See Also:
Workbook.getCellStyleAt(short)
-
setAsActiveCell
void setAsActiveCell()
Sets this cell as the active cell for the worksheet
-
setCellComment
void setCellComment(Comment comment)
Assign a comment to this cell- Parameters:
comment- comment associated with this cell
-
getCellComment
Comment getCellComment()
Returns comment associated with this cell- Returns:
- comment associated with this cell or
nullif not found
-
removeCellComment
void removeCellComment()
Removes the comment for this cell, if there is one.
-
getHyperlink
Hyperlink getHyperlink()
- Returns:
- hyperlink associated with this cell or
nullif not found
-
setHyperlink
void setHyperlink(Hyperlink link)
Assign a hyperlink to this cell- Parameters:
link- hyperlink associated with this cell
-
removeHyperlink
void removeHyperlink()
Removes the hyperlink for this cell, if there is one.
-
getArrayFormulaRange
CellRangeAddress getArrayFormulaRange()
Only valid for array formula cells- Returns:
- range of the array formula group that the cell belongs to.
-
isPartOfArrayFormulaGroup
boolean isPartOfArrayFormulaGroup()
- Returns:
trueif this cell is part of group of cells having a common array formula.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG