public final class XSSFCell extends CellBase
Cells can be numeric, formula-based or string-based (text). The cell type specifies this. String cells cannot contain 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. Only cells that have values should be added.
(电子表格行中单元格的高级表示。单元格可以是数字、基于公式或基于字符串(文本)。单元格类型指定了这一点。字符串单元格不能包含数字,数字单元格不能包含字符串(至少根据我们的模型)。客户端应用程序应该自己进行转换。公式单元格具有公式字符串以及公式结果,可以是数字或字符串。单元格在添加到一行之前应该有它们的编号(从 0 开始)。仅应添加具有值的单元格。)Modifier | Constructor and Description |
---|---|
protected |
XSSFCell(XSSFRow row, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
Construct a XSSFCell.
(构造一个 XSSFCell。)
|
Modifier and Type | Method and Description |
---|---|
void |
copyCellFrom(Cell srcCell, CellCopyPolicy policy)
Copy cell value, formula and style, from srcCell per cell copy policy If srcCell is null, clears the cell value and cell style per cell copy policy This does not shift references in formulas.
(根据单元格复制策略从 srcCell 复制单元格值、公式和样式 如果 srcCell 为空,则根据单元格复制策略清除单元格值和单元格样式 这不会移动公式中的引用。)
|
CellRangeAddress |
getArrayFormulaRange()
Only valid for array formula cells
(仅对数组公式单元格有效)
|
boolean |
getBooleanCellValue()
Get the value of the cell as a boolean.
(获取单元格的值作为布尔值。)
|
CellType |
getCachedFormulaResultType()
Only valid for formula cells
(仅对公式单元格有效)
|
XSSFComment |
getCellComment()
Returns cell comment associated with this cell
(返回与此单元格关联的单元格注释)
|
java.lang.String |
getCellFormula()
Return a formula for the cell, for example,
SUM(C4:E4)
(返回单元格的公式,例如 SUM(C4:E4))
|
protected java.lang.String |
getCellFormula(BaseXSSFEvaluationWorkbook fpb)
package/hierarchy use only - reuse an existing evaluation workbook if available for caching
(仅使用包/层次结构 - 如果可用于缓存,则重用现有的评估工作簿)
|
XSSFCellStyle |
getCellStyle()
Return the cell's style.
(返回单元格的样式。)
|
CellType |
getCellType()
Return the cell type.
(返回单元格类型。)
|
int |
getColumnIndex()
Returns column index of this cell
(返回此单元格的列索引)
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell |
getCTCell()
Returns the xml bean containing information about the cell's location (reference), value, data type, formatting, and formula
(返回包含有关单元格位置(引用)、值、数据类型、格式和公式的信息的 xml bean)
|
java.util.Date |
getDateCellValue()
Get the value of the cell as a date.
(获取单元格的值作为日期。)
|
java.lang.String |
getErrorCellString()
Returns the error message, such as #VALUE!
(返回错误信息,例如#VALUE!)
|
byte |
getErrorCellValue()
Get the value of the cell as an error code.
(获取单元格的值作为错误代码。)
|
XSSFHyperlink |
getHyperlink()
Returns hyperlink associated with this cell
(返回与此单元格关联的超链接)
|
java.time.LocalDateTime |
getLocalDateTimeCellValue()
Get the value of the cell as a LocalDateTime.
(获取单元格的值作为 LocalDateTime。)
|
double |
getNumericCellValue()
Get the value of the cell as a number.
(以数字形式获取单元格的值。)
|
java.lang.String |
getRawValue()
Returns the raw, underlying ooxml value for the cell
(返回单元格的原始基础 ooxml 值)
|
java.lang.String |
getReference()
Returns an A1 style reference to the location of this cell
(返回对此单元格位置的 A1 样式引用)
|
XSSFRichTextString |
getRichStringCellValue()
Get the value of the cell as a XSSFRichTextString
(获取单元格的值作为 XSSFRichTextString)
|
XSSFRow |
getRow()
Returns the row this cell belongs to
(返回此单元格所属的行)
|
int |
getRowIndex()
Returns row index of a row in the sheet that contains this cell
(返回工作表中包含此单元格的行的行索引)
|
protected SharedStringsTable |
getSharedStringSource() |
XSSFSheet |
getSheet()
Returns the sheet 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
(以字符串形式获取单元格的值)
|
protected StylesTable |
getStylesSource() |
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)
Set a error value for the cell
(为单元格设置错误值)
|
void |
setCellErrorValue(FormulaError error)
Set a error value for the cell
(为单元格设置错误值)
|
protected void |
setCellFormulaImpl(java.lang.String formula)
Sets formula for this cell.
(设置此单元格的公式。)
|
protected void |
setCellNum(int num)
Sets column index of this cell
(设置此单元格的列索引)
|
void |
setCellStyle(CellStyle style)
Set the style for the cell.
(设置单元格的样式。)
|
protected void |
setCellType(CellType cellType, BaseXSSFEvaluationWorkbook evalWb)
Needed by bug #62834, which points out getCellFormula() expects an evaluation context or creates a new one, so if there is one in use, it needs to be carried on through.
(错误 #62834 需要,它指出 getCellFormula() 需要一个评估上下文或创建一个新上下文,因此如果有一个正在使用,则需要继续执行。)
|
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.
(设置日期值的特定于实现的方式。)
|
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 str)
Implementation-specific way to set a RichTextString value.
(设置 RichTextString 值的特定于实现的方法。)
|
protected void |
setCellValueImpl(java.lang.String value)
Implementation-specific way to set a string value.
(设置字符串值的特定于实现的方法。)
|
void |
setCTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
Set a new internal xml bean.
(设置一个新的内部 xml bean。)
|
void |
setHyperlink(Hyperlink hyperlink)
Assign a hyperlink to this cell.
(为该单元格分配一个超链接。)
|
java.lang.String |
toString()
Returns a string representation of the cell
(返回单元格的字符串表示形式)
|
void |
updateCellReferencesForShifting(java.lang.String msg) |
getAddress, getValueType, removeFormula, setBlank, setCellFormula, setCellType, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, tryToDeleteArrayFormula
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setCellValue
protected XSSFCell(XSSFRow row, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
row
- the parent row.
(行 - 父行。)
cell
- the xml bean containing information about the cell.
(cell - 包含有关单元格信息的 xml bean。)
protected SpreadsheetVersion getSpreadsheetVersion()
getSpreadsheetVersion
in class
CellBase
(类 CellBase 中的 getSpreadsheetVersion)
@Beta @Internal public void copyCellFrom(Cell srcCell, CellCopyPolicy policy)
XSSFRowShifter
to shift references in formulas.
(根据单元格复制策略从 srcCell 复制单元格值、公式和样式 如果 srcCell 为空,则根据单元格复制策略清除单元格值和单元格样式 这不会移动公式中的引用。使用 XSSFRowShifter 移动公式中的引用。)
srcCell
- The cell to take value, formula and style from
(srcCell - 从中获取值、公式和样式的单元格)
policy
- The policy for copying the information, see
CellCopyPolicy
(policy - 复制信息的策略,请参阅 CellCopyPolicy)
java.lang.IllegalArgumentException
- if copy cell style and srcCell is from a different workbook
(java.lang.IllegalArgumentException - 如果复制单元格样式和 srcCell 来自不同的工作簿)
protected SharedStringsTable getSharedStringSource()
protected StylesTable getStylesSource()
public XSSFSheet getSheet()
public XSSFRow getRow()
public boolean getBooleanCellValue()
For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
(获取单元格的值作为布尔值。对于字符串、数字和错误,我们会抛出异常。对于空白单元格,我们返回 false。)java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is not
CellType.BOOLEAN
,
CellType.BLANK
or
CellType.FORMULA
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型不是 CellType.BOOLEAN、CellType.BLANK 或 CellType.FORMULA)
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.
(value - 将此单元格设置为的布尔值。对于公式,我们将设置预先计算的值,对于布尔值,我们将设置它的值。对于其他类型,我们会将单元格更改为布尔单元格并设置其值。)
public double getNumericCellValue()
For strings we throw an exception. For blank cells we return a 0. For formulas or error cells we return the precalculated value;
(以数字形式获取单元格的值。对于字符串,我们抛出异常。对于空白单元格,我们返回 0。对于公式或错误单元格,我们返回预先计算的值;)java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is
CellType.STRING
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型是 CellType.STRING)
java.lang.NumberFormatException
- if the cell value isn't a parsable
double
.
(java.lang.NumberFormatException - 如果单元格值不是可解析的双精度值。)
for turning this number into a string similar to that which Excel would render this number as.
public 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。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new value to set
(value - 要设置的新值)
public 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
(将单元格的值作为字符串获取 对于数字单元格,我们会抛出异常。对于空白单元格,我们返回一个空字符串。对于不是字符串公式的公式单元格,我们抛出异常)public XSSFRichTextString 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
(获取单元格的值作为 XSSFRichTextString 对于数字单元格,我们抛出异常。对于空白单元格,我们返回一个空字符串。对于公式单元格,如果是字符串,我们将返回预先计算的值,否则返回异常)protected void setCellValueImpl(java.lang.String value)
CellType.STRING
.
(设置字符串值的特定于实现的方法。该值保证为非空值并满足电子表格版本施加的长度限制。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType()(无论哪个合适)将返回 CellType.STRING。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new value to set.
(value - 要设置的新值。)
protected void setCellValueImpl(RichTextString str)
CellType.STRING
.
(设置 RichTextString 值的特定于实现的方法。该值保证为非空,具有非空值,并满足电子表格版本施加的长度限制。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType()(无论哪个合适)将返回 CellType.STRING。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
str
- the new value to set.
(str - 要设置的新值。)
public java.lang.String getCellFormula()
SUM(C4:E4)
(返回单元格的公式,例如 SUM(C4:E4))
java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is not
CellType.FORMULA
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型不是 CellType.FORMULA)
protected java.lang.String getCellFormula(BaseXSSFEvaluationWorkbook fpb)
fpb
- evaluation workbook for reuse, if available, or null to create a new one as needed
(fpb - 评估工作簿以供重用(如果有),或 null 以根据需要创建新工作簿)
java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is not
CellType.FORMULA
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型不是 CellType.FORMULA)
protected void setCellFormulaImpl(java.lang.String formula)
Note, this method only sets the formula string and does not calculate the formula value. To set the precalculated value use CellBase.setCellValue(double)
or CellBase.setCellValue(String)
Note, if there are any shared formulas, his will invalidate any FormulaEvaluator
instances based on this workbook.
setCellFormulaImpl
in class
CellBase
(类 CellBase 中的 setCellFormulaImpl)
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 the operation is not allowed, for example, when the cell is a part of a multi-cell array formula
(java.lang.IllegalStateException - 如果不允许该操作,例如,当单元格是多单元格数组公式的一部分时)
protected void removeFormulaImpl()
CellBase
removeFormulaImpl
in class
CellBase
(类 CellBase 中的 removeFormulaImpl)
public int getColumnIndex()
public int getRowIndex()
public java.lang.String getReference()
public XSSFCellStyle getCellStyle()
Workbook.getCellStyleAt(int)
public void setCellStyle(CellStyle style)
Set the style for the cell. The style should be an XSSFCellStyle created/retreived from the XSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style, use CellUtil.setCellStyleProperties(Cell, java.util.Map)
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.
(样式 - 工作簿中包含的参考。如果值为 null,则删除样式信息,导致单元格使用默认工作簿样式。)
java.lang.IllegalArgumentException
- if style belongs to a different styles source (most likely because style is from a different Workbook)
(java.lang.IllegalArgumentException - 如果样式属于不同的样式源(很可能是因为样式来自不同的工作簿))
Workbook.createCellStyle()
public CellType getCellType()
CellType.FORMULA
for all cells, even though the formula is only defined in the OOXML file for the top left cell of the array.
NOTE: POI does not support data table formulas. Cells in a data table appear to POI as plain cells typed from their cached value.
(返回单元格类型。数组公式中的表为所有单元格返回 CellType.FORMULA,即使该公式仅在数组左上角单元格的 OOXML 文件中定义。注意:POI 不支持数据表公式。数据表中的单元格在 POI 看来是从其缓存值键入的普通单元格。)public CellType getCachedFormulaResultType()
CellType.NUMERIC
,
CellType.STRING
,
CellType.BOOLEAN
,
CellType.ERROR
) depending on the cached value of the formula
((CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, CellType.ERROR) 之一,具体取决于公式的缓存值)
public java.util.Date getDateCellValue()
For strings we throw an exception. For blank cells we return a null.
(获取单元格的值作为日期。对于字符串,我们抛出异常。对于空白单元格,我们返回 null。)java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is
CellType.STRING
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型是 CellType.STRING)
java.lang.NumberFormatException
- if the cell value isn't a parsable
double
.
(java.lang.NumberFormatException - 如果单元格值不是可解析的双精度值。)
for formatting this date into a string similar to how excel does.
public java.time.LocalDateTime getLocalDateTimeCellValue()
For strings we throw an exception. For blank cells we return a null.
(获取单元格的值作为 LocalDateTime。对于字符串,我们抛出异常。对于空白单元格,我们返回 null。)java.lang.IllegalStateException
- if the cell type returned by
getCellType()
is
CellType.STRING
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型是 CellType.STRING)
java.lang.NumberFormatException
- if the cell value isn't a parsable
double
.
(java.lang.NumberFormatException - 如果单元格值不是可解析的双精度值。)
for formatting this date into a string similar to how excel does.
protected 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。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new date to set
(value - 要设置的新日期)
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
.
(设置日期值的特定于实现的方式。值保证为非空。该实现预计会相应地调整单元类型,以便在调用 getCellType() 或 getCachedFormulaResultType() 之后返回 CellType.NUMERIC。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new date to set
(value - 要设置的新日期)
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
.
(设置日历值的特定于实现的方法。值保证为非空。该实现预计会相应地调整单元类型,以便在调用 getCellType() 或 getCachedFormulaResultType() 之后返回 CellType.NUMERIC。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new calendar value to set
(value - 要设置的新日历值)
public java.lang.String getErrorCellString() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cell type returned by
getCellType()
isn't
CellType.ERROR
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型不是 CellType.ERROR)
FormulaError
public byte getErrorCellValue() throws java.lang.IllegalStateException
For strings, numbers, and booleans, we throw an exception. For blank cells we return a 0.
(获取单元格的值作为错误代码。对于字符串、数字和布尔值,我们会抛出异常。对于空白单元格,我们返回 0。)java.lang.IllegalStateException
- if the cell type returned by
getCellType()
isn't
#ERROR
(java.lang.IllegalStateException - 如果 getCellType() 返回的单元格类型不是 #ERROR)
FormulaError
public void setCellErrorValue(byte errorCode)
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.
(errorCode - 将此单元格设置为的错误值。对于公式,我们将设置预先计算的值,对于错误,我们将设置其值。对于其他类型,我们会将单元格更改为错误单元格并设置其值。)
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.
(error - 将此单元格设置为的错误值。对于公式,我们将设置预先计算的值,对于错误,我们将设置其值。对于其他类型,我们会将单元格更改为错误单元格并设置其值。)
public void setAsActiveCell()
protected void setCellNum(int num)
num
- column index of this cell
(num - 此单元格的列索引)
protected void setCellTypeImpl(CellType cellType)
CellBase
setCellTypeImpl
in class
CellBase
(类 CellBase 中的 setCellTypeImpl)
cellType
- new cell type. Guaranteed non-null, not _NONE.
(cellType - 新的细胞类型。保证非空,而不是_NONE。)
protected void setCellType(CellType cellType, BaseXSSFEvaluationWorkbook evalWb)
cellType
-
(细胞类型 -)
evalWb
- BaseXSSFEvaluationWorkbook already in use, or null if a new implicit one should be used
(evalWb - BaseXSSFEvaluationWorkbook 已在使用中,如果应使用新的隐式工作簿,则为 null)
public java.lang.String toString()
Formula cells return the formula string, rather than the formula result. Dates are displayed in dd-MMM-yyyy format Errors are displayed as #ERR<errIdx>
(返回单元格的字符串表示形式 公式单元格返回公式字符串,而不是公式结果。日期以 dd-MMM-yyyy 格式显示 错误显示为 #ERRtoString
in class
java.lang.Object
public java.lang.String getRawValue()
If the cell contains a string, then this value is an index into the shared string table, pointing to the actual string value. Otherwise, the value of the cell is expressed directly in this element. Cells containing formulas express the last calculated result of the formula in this element.
(返回单元格的原始底层 ooxml 值 如果单元格包含字符串,则此值是共享字符串表的索引,指向实际字符串值。否则,单元格的值直接在此元素中表示。包含公式的单元格表示此元素中公式的最后计算结果。)null
for blank cells.
(底层 CTCell bean 中包含的原始单元格值,对于空白单元格为 null。)
public XSSFComment getCellComment()
null
(与此单元格关联的单元格注释或 null)
public void setCellComment(Comment comment)
comment
- the XSSFComment associated with this cell
(comment - 与此单元格关联的 XSSFComment)
public void removeCellComment()
public XSSFHyperlink getHyperlink()
null
if not found
(与此单元格关联的超链接,如果未找到,则为 null)
public void setHyperlink(Hyperlink hyperlink)
hyperlink
- the hyperlink to associate with this cell
(hyperlink - 与此单元格关联的超链接)
public void removeHyperlink()
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell getCTCell()
@Internal public void setCTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell cell)
public CellRangeAddress getArrayFormulaRange()
Cell
public boolean isPartOfArrayFormulaGroup()
true
if this cell is part of group of cells having a common array formula.
(如果此单元格是具有公共数组公式的单元格组的一部分,则为 true。)
public void updateCellReferencesForShifting(java.lang.String msg)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.