Skip to main content

Cell Object单元格对象

Cell objects are plain JS objects with keys and values following the convention:单元格对象是普通JS对象,其键和值符合约定:

KeyDescription描述
Core Cell Properties核心单元属性 (More Info)
vraw value (number, string, Date object, boolean)原始值(数字、字符串、日期对象、布尔值)
ttype: b Boolean, e Error, n Number, d Date, s Text, z Stub类型:b布尔值、e错误、n数字、d日期、s文本、z存根
Number Formats数字格式 (More Info)
znumber format string associated with the cell (if requested)与单元格关联的数字格式字符串(如果需要)
wformatted text (if applicable)格式化文本(如适用)
Formulae公式 (More Info)
fcell formula encoded as an A1-style string (if applicable)编码为A1样式字符串的单元格公式(如果适用)
Frange of enclosing array if formula is array formula (if applicable)如果公式是数组公式,则封闭数组的范围(如果适用)
Dif true, array formula is dynamic (if applicable)如果为true,则数组公式是动态的(如果适用)
Other Cell Properties其他单元格属性 (More Info)
lcell hyperlink and tooltip单元格超链接和工具提示 (More Info)
ccell comments单元格注释 (More Info)
rrich text encoding (if applicable)富文本编码(如适用)
hHTML rendering of the rich text (if applicable)富文本的HTML呈现(如果适用)
sthe style/theme of the cell (if applicable)单元格的样式/主题(如果适用)

Built-in export utilities (such as the CSV exporter) will use the w text if it is available. 内置导出实用程序(如CSV导出器)将使用w文本(如果可用)。To change a value, be sure to delete cell.w (or set it to undefined) before attempting to export. 要更改值,请确保在尝试导出之前删除cell.w(或将其设置为undefined)。The utilities will regenerate the w text from the number format (cell.z) and the raw value if possible.如果可能,实用程序将从数字格式(cell.z)和原始值重新生成w文本。

The actual array formula is stored in the f field of the first cell in the array range. 实际数组公式存储在数组范围中第一个单元格的f字段中。Other cells in the range will omit the f field.范围中的其他单元格将忽略f字段。

Data Types数据类型

The raw value is stored in the v value property, interpreted based on the t type property. 原始值存储在v值属性中,根据t类型属性进行解释。This separation allows for representation of numbers as well as numeric text. 这种分离允许数字和数字文本的表示。There are 6 valid cell types:有6种有效的单元格类型:

Type类型Description描述
bBoolean: value interpreted as JS boolean:值被解释为JSboolean
eError: value is a numeric code and w property stores common name :值是数字代码,w属性存储公共名称**
nNumber: value is a JS :值是JSnumber **
dDate: value is a JS Date object or string to be parsed as Date:值是JSDate对象或被解析为日期的字符串 **
sText: value interpreted as JS string and written as text:值被解析为JSstring并写为文本 **
zStub: blank stub cell that is ignored by data processing utilities:被数据处理实用程序忽略的空白存根单元格 **
Error values and interpretation误差值和解释 (click to show)
ValueError Meaning错误含义
0x00#NULL!
0x07#DIV/0!
0x0F#VALUE!
0x17#REF!
0x1D#NAME?
0x24#NUM!
0x2A#N/A
0x2B#GETTING_DATA

Type n is the Number type. 类型n是数字类型。This includes all forms of data that Excel stores as numbers, such as dates/times and Boolean fields. 这包括Excel存储为数字的所有形式的数据,例如日期/时间和布尔字段。Excel exclusively uses data that can be fit in an IEEE754 floating point number, just like JS Number, so the v field holds the raw number. Excel专门使用可以放入IEEE754浮点数中的数据,就像JS数字一样,因此v字段保存原始数字。The w field holds formatted text. w字段保存格式化文本。Dates are stored as numbers by default and converted with XLSX.SSF.parse_date_code.默认情况下,日期存储为数字,并使用XXLSX.SSF.parse_date_code进行转换。

Type d is the Date type, generated only when the option cellDates is passed. 类型d是日期类型,仅当传递选项cellDates时生成。Since JSON does not have a natural Date type, parsers are generally expected to store ISO 8601 Date strings like you would get from date.toISOString(). 由于JSON没有自然的日期类型,解析器通常需要存储ISO 8601日期字符串,就像从date.toISOString()获得的一样。On the other hand, writers and exporters should be able to handle date strings and JS Date objects. 另一方面,编写器和导出器应该能够处理日期字符串和JS日期对象。Note that Excel disregards timezone modifiers and treats all dates in the local timezone. 请注意,Excel忽略时区修饰符,并处理本地时区中的所有日期。The library does not correct for this error. 库无法更正此错误。Dates are covered in more detail in the Dates section日期部分详细介绍了日期。

Type s is the String type. 类型s是字符串类型。Values are explicitly stored as text. 值显式存储为文本。Excel will interpret these cells as "number stored as text". Excel将这些单元格解释为“以文本形式存储的数字”。Generated Excel files automatically suppress that class of error, but other formats may elicit errors.生成的Excel文件自动抑制该类错误,但其他格式可能会引发错误。

Type z represents blank stub cells. z型表示空白存根单元格。They are generated in cases where cells have no assigned value but hold comments or other metadata. 它们是在单元格没有赋值但包含注释或其他元数据的情况下生成的。They are ignored by the core library data processing utility functions. 它们被核心库数据处理实用程序函数忽略。By default these cells are not generated; the parser sheetStubs option must be set to true.默认情况下,不会生成这些单元格;解析器sheetStubs选项必须设置为true