public class HSSFCell extends CellBase
Cells should have their number (0 based) before being added to a row. Only cells that have values should be added.
(电子表格行中单元格的高级表示。单元格可以是数字、基于公式或基于字符串(文本)。单元格类型指定了这一点。字符串单元格不能包含数字,数字单元格不能包含字符串(至少根据我们的模型)。客户端应用程序应该自己进行转换。公式单元格具有公式字符串以及公式结果,可以是数字或字符串。单元格在添加到一行之前应该有它们的编号(从 0 开始)。仅应添加具有值的单元格。)Modifier and Type | Field and Description |
---|---|
static short |
ENCODING_COMPRESSED_UNICODE |
static short |
ENCODING_UNCHANGED |
static short |
ENCODING_UTF_16 |
static int |
LAST_COLUMN_NUMBER
The maximum number of columns in BIFF8
(BIFF8 中的最大列数)
|
Modifier | Constructor and Description |
---|---|
protected |
HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval)
Creates an HSSFCell from a CellValueRecordInterface.
(从 CellValueRecordInterface 创建一个 HSSFCell。)
|
protected |
HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col)
Creates new Cell - Should only be called by HSSFRow.
(创建新单元 - 只能由 HSSFRow 调用。)
|
protected |
HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type)
Creates new Cell - Should only be called by HSSFRow.
(创建新单元 - 只能由 HSSFRow 调用。)
|
Modifier and Type | Method and Description |
---|---|
CellRangeAddress |
getArrayFormulaRange()
Only valid for array formula cells
(仅对数组公式单元格有效)
|
boolean |
getBooleanCellValue()
get the value of the cell as a boolean.
(获取单元格的值作为布尔值。)
|
protected InternalWorkbook |
getBoundWorkbook()
Returns the Workbook that this Cell is bound to
(返回此单元格绑定到的工作簿)
|
CellType |
getCachedFormulaResultType()
Only valid for formula cells
(仅对公式单元格有效)
|
HSSFComment |
getCellComment()
Returns comment associated with this cell
(返回与此单元格关联的评论)
|
java.lang.String |
getCellFormula()
Return a formula for the cell, for example,
SUM(C4:E4)
(返回单元格的公式,例如 SUM(C4:E4))
|
HSSFCellStyle |
getCellStyle()
get the style for the cell.
(获取单元格的样式。)
|
CellType |
getCellType()
get the cells type (numeric, formula or string)
(获取单元格类型(数字、公式或字符串))
|
protected CellValueRecordInterface |
getCellValueRecord()
Should only be used by HSSFSheet and friends.
(只能由 HSSFSheet 和朋友使用。)
|
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.
(获取单元格的值作为错误代码。)
|
HSSFHyperlink |
getHyperlink() |
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.
(以数字形式获取单元格的值。)
|
HSSFRichTextString |
getRichStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception.
(将单元格的值作为字符串获取 - 对于数字单元格,我们会抛出异常。)
|
HSSFRow |
getRow()
Returns the HSSFRow this cell belongs to
(返回此单元格所属的 HSSFRow)
|
int |
getRowIndex()
Returns row index of a row in the sheet that contains this cell
(返回工作表中包含此单元格的行的行索引)
|
HSSFSheet |
getSheet()
Returns the HSSFSheet this cell belongs to
(返回此单元格所属的 HSSFSheet)
|
protected SpreadsheetVersion |
getSpreadsheetVersion()
Get the spreadsheet version for the given implementation.
(获取给定实现的电子表格版本。)
|
java.lang.String |
getStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception.
(将单元格的值作为字符串获取 - 对于数字单元格,我们会抛出异常。)
|
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)
Deprecated.
3.15 beta 2. Use
(已弃用。 3.15 beta 2. 改用 setCellErrorValue(FormulaError)。)
setCellErrorValue(FormulaError) instead.
|
void |
setCellErrorValue(FormulaError error)
set a error value for the cell
(为单元格设置错误值)
|
protected void |
setCellFormulaImpl(java.lang.String formula)
Implementation-specific setting the formula.
(特定于实现的设置公式。)
|
void |
setCellStyle(CellStyle style)
Set the style for the cell.
(设置单元格的样式。)
|
void |
setCellStyle(HSSFCellStyle style) |
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.
(设置日期值的特定于实现的方式。)
|
protected 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 value)
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 |
setHyperlink(Hyperlink hyperlink)
Assign a hyperlink to this cell.
(为该单元格分配一个超链接。)
|
java.lang.String |
toString()
Returns a string representation of the cell This method returns a simple representation, anything more complex should be in user code, with knowledge of the semantics of the sheet being processed.
(返回单元格的字符串表示此方法返回一个简单的表示,任何更复杂的都应该在用户代码中,并了解正在处理的工作表的语义。)
|
protected void |
updateCellNum(short num)
Updates the cell record's idea of what column it belongs in (0 based)
(更新单元格记录对其所属列的概念(基于 0))
|
getAddress, getValueType, removeFormula, setBlank, setCellFormula, setCellType, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, setCellValue, tryToDeleteArrayFormula
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setCellValue
public static final int LAST_COLUMN_NUMBER
public static final short ENCODING_UNCHANGED
public static final short ENCODING_COMPRESSED_UNICODE
public static final short ENCODING_UTF_16
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col)
When the cell is initially created it is set to CellType.BLANK
. Cell types can be changed/overwritten by calling setCellValue with the appropriate type as a parameter although conversions from one type to another may be prohibited.
book
- - Workbook record of the workbook containing this cell
(book - - 包含此单元格的工作簿的工作簿记录)
sheet
- - Sheet record of the sheet containing this cell
(sheet - - 包含此单元格的工作表的工作表记录)
row
- - the row of this cell
(row - - 此单元格的行)
col
- - the column for this cell
(col - - 此单元格的列)
HSSFRow.createCell(int)
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type)
book
- - Workbook record of the workbook containing this cell
(book - - 包含此单元格的工作簿的工作簿记录)
sheet
- - Sheet record of the sheet containing this cell
(sheet - - 包含此单元格的工作表的工作表记录)
row
- - the row of this cell
(row - - 此单元格的行)
col
- - the column for this cell
(col - - 此单元格的列)
type
- - Type of cell
(type - - 单元格类型)
HSSFRow.createCell(int,CellType)
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval)
book
- - Workbook record of the workbook containing this cell
(book - - 包含此单元格的工作簿的工作簿记录)
sheet
- - Sheet record of the sheet containing this cell
(sheet - - 包含此单元格的工作表的工作表记录)
cval
- - the Cell Value Record we wish to represent
(cval - - 我们希望表示的单元格值记录)
protected SpreadsheetVersion getSpreadsheetVersion()
getSpreadsheetVersion
in class
CellBase
(类 CellBase 中的 getSpreadsheetVersion)
public HSSFSheet getSheet()
public HSSFRow getRow()
protected InternalWorkbook getBoundWorkbook()
public int getRowIndex()
Cell
protected void updateCellNum(short num)
num
- the new cell number
(num - 新的手机号码)
public int getColumnIndex()
Cell
protected void setCellTypeImpl(CellType cellType)
CellBase
setCellTypeImpl
in class
CellBase
(类 CellBase 中的 setCellTypeImpl)
cellType
- new cell type. Guaranteed non-null, not _NONE.
(cellType - 新的细胞类型。保证非空,而不是_NONE。)
public CellType getCellType()
protected 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 - 要设置的新值)
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
.
In HSSF, only the number of days is stored. The fractional part is ignored.
(设置日期值的特定于实现的方式。值保证为非空。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType() 将返回 CellType.NUMERIC。在 HSSF 中,仅存储天数。小数部分被忽略。)setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new date to set
(value - 要设置的新日期)
DateUtil
,
DateUtil
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
.
In HSSF, only the number of days is stored. The fractional part is ignored.
(设置日期值的特定于实现的方式。值保证为非空。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType() 将返回 CellType.NUMERIC。在 HSSF 中,仅存储天数。小数部分被忽略。)setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new date to set
(value - 要设置的新日期)
DateUtil
,
DateUtil
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 - 要设置的新日历值)
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 value)
CellType.STRING
.
(设置 RichTextString 值的特定于实现的方法。该值保证为非空,具有非空值,并满足电子表格版本施加的长度限制。该实现预计会相应地调整单元类型,以便在此调用之后 getCellType() 或 getCachedFormulaResultType()(以适当的为准)将返回 CellType.STRING。)
setCellValueImpl
in class
CellBase
(类 CellBase 中的 setCellValueImpl)
value
- the new value to set.
(value - 要设置的新值。)
protected void setCellFormulaImpl(java.lang.String formula)
setCellFormulaImpl
in class
CellBase
(类 CellBase 中的 setCellFormulaImpl)
protected void removeFormulaImpl()
CellBase
removeFormulaImpl
in class
CellBase
(类 CellBase 中的 removeFormulaImpl)
public java.lang.String getCellFormula()
Cell
SUM(C4:E4)
(返回单元格的公式,例如 SUM(C4:E4))
public double getNumericCellValue()
HSSFDataFormatter
for turning this number into a string similar to that which Excel would render this number as.
(以数字形式获取单元格的值。对于字符串,我们抛出异常。对于空白单元格,我们返回 0。请参阅 HSSFDataFormatter 以将此数字转换为类似于 Excel 将此数字呈现为的字符串。)
for turning this number into a string similar to that which Excel would render this number as.
public java.util.Date getDateCellValue()
HSSFDataFormatter
for formatting this date into a string similar to how excel does.
(获取单元格的值作为日期。对于字符串,我们抛出异常。对于空白单元格,我们返回 null。请参阅 HSSFDataFormatter 以将此日期格式化为类似于 excel 的字符串。)
for formatting this date into a string similar to how excel does.
public java.time.LocalDateTime getLocalDateTimeCellValue()
HSSFDataFormatter
for formatting this date into a string similar to how excel does.
(获取单元格的值作为 LocalDateTime。对于字符串,我们抛出异常。对于空白单元格,我们返回 null。请参阅 HSSFDataFormatter 以将此日期格式化为类似于 excel 的字符串。)
for formatting this date into a string similar to how excel does.
public java.lang.String getStringCellValue()
public HSSFRichTextString getRichStringCellValue()
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 void setCellErrorValue(byte errorCode)
setCellErrorValue(FormulaError)
instead.
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. For error code byte, see
FormulaError
.
(errorCode - 将此单元格设置为的错误值。对于公式,我们将设置预先计算的值,对于错误,我们将设置其值。对于其他类型,我们会将单元格更改为错误单元格并设置其值。有关错误代码字节,请参阅 FormulaError。)
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 boolean getBooleanCellValue()
public byte getErrorCellValue()
for error codes
public void setCellStyle(CellStyle style)
Set the style for the cell. The style should be an HSSFCellStyle created/retreived from the HSSFWorkbook.
To change the style of a cell without affecting other cells that use the same style, use CellUtil.setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, java.util.Map)
style
- reference contained in the workbook
(样式 - 工作簿中包含的参考)
HSSFWorkbook.createCellStyle()
,
HSSFWorkbook.getCellStyleAt(int)
public void setCellStyle(HSSFCellStyle style)
public HSSFCellStyle getCellStyle()
workbook.getCellStyleAt(0)
(单元格的样式。始终不为空。默认单元格样式的索引为零,可以通过 workbook.getCellStyleAt(0) 获得)
HSSFWorkbook.getCellStyleAt(int)
protected CellValueRecordInterface getCellValueRecord()
public void setAsActiveCell()
public java.lang.String toString()
toString
in class
java.lang.Object
public void setCellComment(Comment comment)
comment
- comment associated with this cell
(评论 - 与此单元格关联的评论)
public HSSFComment getCellComment()
public void removeCellComment()
public HSSFHyperlink getHyperlink()
null
if not found
(与此单元格关联的超链接,如果未找到,则为 null)
public void setHyperlink(Hyperlink hyperlink)
hyperlink
- hyperlink associated with this cell
(超链接 - 与此单元格关联的超链接)
public void removeHyperlink()
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 CellRangeAddress getArrayFormulaRange()
Cell
public boolean isPartOfArrayFormulaGroup()
true
if this cell is part of group of cells having a common array formula.
(如果此单元格是具有公共数组公式的单元格组的一部分,则为 true。)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.