Constructor and Description |
---|
CellBase() |
Modifier and Type | Method and Description |
---|---|
CellAddress |
getAddress()
Gets the address of this cell
|
protected abstract SpreadsheetVersion |
getSpreadsheetVersion()
Get the spreadsheet version for the given implementation.
|
protected CellType |
getValueType()
Get value type of this cell.
|
void |
removeFormula()
Removes formula, if any.
|
protected abstract void |
removeFormulaImpl()
Implementation-specific removal of the formula.
|
void |
setBlank()
Removes formula and value from the cell, and sets its type to
CellType.BLANK . |
void |
setCellFormula(java.lang.String formula)
Sets formula for this cell.
|
protected abstract void |
setCellFormulaImpl(java.lang.String formula)
Implementation-specific setting the formula.
|
void |
setCellType(CellType cellType)
Set the cells type (blank, numeric, boolean, error or string).
|
protected abstract void |
setCellTypeImpl(CellType cellType)
Implementation-specific logic
|
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(java.time.LocalDateTime value)
Converts the supplied date to its equivalent Excel numeric value and sets
that into 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.
|
protected abstract void |
setCellValueImpl(java.util.Calendar value)
Implementation-specific way to set a calendar value.
|
protected abstract void |
setCellValueImpl(java.util.Date value)
Implementation-specific way to set a date value.
|
protected abstract void |
setCellValueImpl(double value)
Implementation-specific way to set a numeric value.
|
protected abstract void |
setCellValueImpl(java.time.LocalDateTime value)
Implementation-specific way to set a date value.
|
protected abstract void |
setCellValueImpl(RichTextString value)
Implementation-specific way to set a RichTextString value.
|
protected abstract void |
setCellValueImpl(java.lang.String value)
Implementation-specific way to set a string value.
|
void |
tryToDeleteArrayFormula(java.lang.String message)
Called when this an array formula in this cell is deleted.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getArrayFormulaRange, getBooleanCellValue, getCachedFormulaResultType, getCellComment, getCellFormula, getCellStyle, getCellType, getColumnIndex, getDateCellValue, getErrorCellValue, getHyperlink, getLocalDateTimeCellValue, getNumericCellValue, getRichStringCellValue, getRow, getRowIndex, getSheet, getStringCellValue, isPartOfArrayFormulaGroup, removeCellComment, removeHyperlink, setAsActiveCell, setCellComment, setCellErrorValue, setCellStyle, setCellValue, setCellValue, setHyperlink
public final void setCellType(CellType 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.
Conversion rules:
to NUMERIC: numeric value is left as is. True converts to 1.0, false converts to 0. otherwise, the value is set to 0. Formula is removed.
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.
If cell is a member of an array formula group containing more than 1 cell, an IllegalStateException
is thrown. If the array formula group contains only this cell, it is removed.
Passing CellType.FORMULA
is illegal and will result in an IllegalArgumentException
.
setCellType
in interface Cell
public void setBlank()
CellType.BLANK
.
Preserves comments and hyperlinks.
While Cell.setCellType(CellType)
exists, is an alias for setCellType(CellType.BLANK)
.public CellAddress getAddress()
getAddress
in interface Cell
A1
style address of this cellprotected abstract void setCellTypeImpl(CellType cellType)
cellType
- new cell type. Guaranteed non-null, not _NONE.public final void tryToDeleteArrayFormula(java.lang.String message)
The purpose of this method is to validate the cell state prior to modification.
message
- a customized exception message for the case if deletion of the cell is impossible. If null, a
default message will be generatedjava.lang.IllegalStateException
- if modification is not allowed
Note. Exposing this to public is ugly. Needed for methods like Sheet#shiftRows.setCellType(CellType)
,
setCellFormula(String)
,
Row.removeCell(org.apache.poi.ss.usermodel.Cell)
,
Sheet.removeRow(org.apache.poi.ss.usermodel.Row)
,
Sheet.shiftRows(int, int, int)
,
Sheet.addMergedRegion(org.apache.poi.ss.util.CellRangeAddress)
public final void setCellFormula(java.lang.String formula) throws FormulaParseException, java.lang.IllegalStateException
If formula
is not null, sets or updates the formula. If formula
is null, removes the formula.
Or use Cell.removeFormula()
to remove the formula.
Note, this method only sets the formula string and does not calculate the formula value.
To set the precalculated value use Cell.setCellValue(double)
.
If the cell was blank, sets value to 0. Otherwise, preserves the value as precalculated.
setCellFormula
in interface Cell
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.IllegalStateException
- if this cell is a part of an array formula group containing other cellsCell.removeFormula()
protected abstract void setCellFormulaImpl(java.lang.String formula)
formula
- protected final CellType getValueType()
getCellType() == CellType.FORMULA ? getCachedFormulaResultType() : getCellType()
This is meant as a temporary helper method until the time when value type is decoupled from the formula.
public final void removeFormula()
removeFormula
in interface Cell
protected abstract void removeFormulaImpl()
public void setCellValue(double value)
setCellValue
in interface Cell
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.protected abstract 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
.value
- the new value to setpublic void setCellValue(java.util.Date value)
Cell
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 besides CellType.NUMERIC
. POI
does not attempt to replicate this behaviour. To make a numeric cell
display as a date, use Cell.setCellStyle(CellStyle)
etc.
setCellValue
in interface Cell
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.public void setCellValue(java.time.LocalDateTime value)
Cell
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 besides CellType.NUMERIC
. POI
does not attempt to replicate this behaviour. To make a numeric cell
display as a date, use Cell.setCellStyle(CellStyle)
etc.
setCellValue
in interface Cell
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.protected abstract 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
.value
- the new date to setprotected abstract 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
.value
- the new date to setpublic 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.
setCellValue
in interface Cell
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.protected abstract 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
.value
- the new calendar value to setpublic void setCellValue(java.lang.String value)
setCellValue
in interface Cell
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.protected abstract void setCellValueImpl(java.lang.String value)
CellType.STRING
.value
- the new value to set.public void setCellValue(RichTextString value)
setCellValue
in interface Cell
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.protected abstract void setCellValueImpl(RichTextString value)
CellType.STRING
.value
- the new value to set.protected abstract SpreadsheetVersion getSpreadsheetVersion()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.