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 .
(从单元格中删除公式和值,并将其类型设置为 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.
(将提供的日期转换为其等效的 Excel 数值并将其设置到单元格中。)
|
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.
(将提供的日期转换为其等效的 Excel 数值并将其设置到单元格中。)
|
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.
(设置 RichTextString 值的特定于实现的方法。)
|
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
(接口 Cell 中的 setCellType)
public void setBlank()
CellType.BLANK
. Preserves comments and hyperlinks. While
Cell.setCellType(CellType)
exists, is an alias for
setCellType(CellType.BLANK)
.
(从单元格中删除公式和值,并将其类型设置为 CellType.BLANK。保留评论和超链接。虽然 Cell.setCellType(CellType) 存在,但它是 setCellType(CellType.BLANK) 的别名。)
public CellAddress getAddress()
getAddress
in interface
Cell
(接口 Cell 中的 getAddress)
A1
style address of this cell
(此单元格的 A1 样式地址)
protected abstract void setCellTypeImpl(CellType cellType)
cellType
- new cell type. Guaranteed non-null, not _NONE.
(cellType - 新的细胞类型。保证非空,而不是_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 generated
(message - 如果无法删除单元格,则自定义异常消息。如果为null,将生成默认消息)
java.lang.IllegalStateException
- if modification is not allowed Note. Exposing this to public is ugly. Needed for methods like Sheet#shiftRows.
(java.lang.IllegalStateException - 如果不允许修改 注意。把这个暴露给公众是丑陋的。需要像 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.
(设置此单元格的公式。如果公式不为空,则设置或更新公式。如果公式为空,则删除公式。或使用 Cell.removeFormula() 删除公式。注意,此方法只设置公式字符串,不计算公式值。要设置预先计算的值,请使用 Cell.setCellValue(double)。如果单元格为空白,则将值设置为 0。否则,将值保留为预先计算的值。)setCellFormula
in interface
Cell
(接口 Cell 中的 setCellFormula)
formula
- the formula to set, e.g.
"SUM(C4:E4)"
. If the argument is
null
then the current formula is removed.
(公式 - 要设置的公式,例如“SUM(C4:E4)”。如果参数为空,则删除当前公式。)
FormulaParseException
- if the formula has incorrect syntax or is otherwise invalid
(FormulaParseException - 如果公式的语法不正确或无效)
java.lang.IllegalStateException
- if this cell is a part of an array formula group containing other cells
(java.lang.IllegalStateException - 如果此单元格是包含其他单元格的数组公式组的一部分)
Cell.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.
(获取此单元格的值类型。可以返回空白、数字、字符串、布尔值或错误。对于类型与公式强耦合的当前实现,等效于 getCellType() == CellType.FORMULA 吗? getCachedFormulaResultType() : getCellType() 这意味着在值类型与公式分离之前作为临时辅助方法。)public final void removeFormula()
removeFormula
in interface
Cell
(接口 Cell 中的 removeFormula)
protected abstract void removeFormulaImpl()
public void setCellValue(double value)
setCellValue
in interface
Cell
(接口 Cell 中的 setCellValue)
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.
(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 保证是有效的(非 NaN)双精度。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType() 将返回 CellType.NUMERIC。)
value
- the new value to set
(value - 要设置的新值)
public 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
(接口 Cell 中的 setCellValue)
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.
(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
(接口 Cell 中的 setCellValue)
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.
(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
.
(设置日期值的特定于实现的方式。值保证为非空。该实现预计会相应地调整单元类型,以便在调用 getCellType() 或 getCachedFormulaResultType() 之后返回 CellType.NUMERIC。)
value
- the new date to set
(value - 要设置的新日期)
protected 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
.
(设置日期值的特定于实现的方式。值保证为非空。该实现预计会相应地调整单元类型,以便在调用 getCellType() 或 getCachedFormulaResultType() 之后返回 CellType.NUMERIC。)
value
- the new date to set
(value - 要设置的新日期)
public 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
(接口 Cell 中的 setCellValue)
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.
(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
.
(设置日历值的特定于实现的方法。值保证为非空。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType() 将返回 CellType.NUMERIC。)
value
- the new calendar value to set
(value - 要设置的新日历值)
public void setCellValue(java.lang.String value)
setCellValue
in interface
Cell
(接口 Cell 中的 setCellValue)
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.
(value - 将单元格设置为的值。对于公式,我们将设置公式字符串,对于字符串单元格,我们将设置其值。对于其他类型,我们会将单元格更改为字符串单元格并设置其值。如果值为 null,那么我们会将单元格更改为空白单元格。)
protected abstract void setCellValueImpl(java.lang.String value)
CellType.STRING
.
(设置字符串值的特定于实现的方法。该值保证为非空值并满足电子表格版本施加的长度限制。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType()(以适当的为准)将返回 CellType.STRING。)
value
- the new value to set.
(value - 要设置的新值。)
public void setCellValue(RichTextString value)
setCellValue
in interface
Cell
(接口 Cell 中的 setCellValue)
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.
(value - 将单元格设置为的值。对于公式,我们将设置公式字符串,对于字符串单元格,我们将设置其值。对于其他类型,我们会将单元格更改为字符串单元格并设置其值。如果值为 null,那么我们会将单元格更改为空白单元格。)
protected abstract void setCellValueImpl(RichTextString value)
CellType.STRING
.
(设置 RichTextString 值的特定于实现的方法。该值保证为非空,具有非空值,并满足电子表格版本施加的长度限制。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType()(无论哪个合适)将返回 CellType.STRING。)
value
- the new value to set.
(value - 要设置的新值。)
protected abstract SpreadsheetVersion getSpreadsheetVersion()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.