Skip to main content

Sheet Objects工作表对象

Excel supports 4 different types of "sheets":Excel支持4种不同类型的“工作表”:

  • "worksheets": normal sheets
  • "chartsheets": full-tab charts
  • "macrosheets": legacy (pre-VBA) macros
  • "dialogsheets": legacy (pre-VBA) dialogs

Generic Sheet Object通用工作表对象

Generic sheets are plain JavaScript objects. 通用表是普通的JavaScript对象。Each key that does not start with ! is an A1-style address whose corresponding value is a cell object.每个不以!开头的键是A1样式的地址,其对应值为单元格对象。

sheet[address] returns the cell object for the specified address.返回指定地址的单元格对象。

Sheet Properties工作表属性

Each key starts with !. 每个键都以!开头。The properties are accessible as sheet[key].属性可作为sheet[key]访问。

  • sheet['!ref']: A-1 based range representing the sheet range. :基于A-1的范围,表示工作表范围。Functions that work with sheets should use this parameter to determine the range. 处理工作表的函数应使用此参数来确定范围。Cells that are assigned outside of the range are not processed. 不处理分配在范围之外的单元格。In particular, when writing a sheet by hand, cells outside of the range are not included特别是,当用手书写纸张时,不包括范围外的单元格

    Functions that handle sheets should test for the presence of !ref field. 处理表单的函数应测试是否存在!ref字段。If the !ref is omitted or is not a valid range, functions are free to treat the sheet as empty or attempt to guess the range. 如果!ref被省略或不是有效范围,函数可以自由将工作表视为空或尝试猜测范围。The standard utilities that ship with this library treat sheets as empty (for example, the CSV output is empty string).此库附带的标准实用程序将工作表视为空(例如,CSV输出为空字符串)。

    When reading a worksheet with the sheetRows property set, the ref parameter will use the restricted range. 当读取设置了sheetRows属性的工作表时,ref参数将使用受限范围。The original range is set at ws['!fullref']原始范围设置为ws['!fullref']

  • sheet['!margins']: Object representing the page margins. :表示页边距的对象。The default values follow Excel's "normal" preset. 默认值遵循Excel的“常规”预设。Excel also has a "wide" and a "narrow" preset but they are stored as raw measurements. Excel也有“宽”和“窄”预设,但它们存储为原始测量值。The main properties are listed below:主要性能如下:

Page margin details页边距详细信息 (click to show)
keydescription描述"normal""wide""narrow"
leftleft margin (inches)左边距(英寸)0.71.00.25
rightright margin (inches)右边距(英寸)0.71.00.25
toptop margin (inches)上边距(英寸)0.751.00.75
bottombottom margin (inches)底部边距(英寸)0.751.00.75
headerheader margin (inches)页眉边距(英寸)0.30.50.3
footerfooter margin (inches)页脚边距(英寸)0.30.50.3
/* Set worksheet sheet to "normal" */
ws["!margins"]={left:0.7, right:0.7, top:0.75,bottom:0.75,header:0.3,footer:0.3}
/* Set worksheet sheet to "wide" */
ws["!margins"]={left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5,footer:0.5}
/* Set worksheet sheet to "narrow" */
ws["!margins"]={left:0.25,right:0.25,top:0.75,bottom:0.75,header:0.3,footer:0.3}

Worksheet Object工作表对象

In addition to the aforementioned sheet keys, worksheets also add:除了上述工作表索引外,工作表还添加了:

  • ws['!cols']: array of column properties objects. :列属性对象的数组。Column widths are actually stored in files in a normalized manner, measured in terms of the "Maximum Digit Width" (the largest width of the rendered digits 0-9, in pixels). 列宽实际上以规范化的方式存储在文件中,根据“最大数字宽度”(渲染数字的最大宽度0-9,以像素为单位)进行测量。When parsed, the column objects store the pixel width in the wpx field, character width in the wch field, and the maximum digit width in the MDW field.解析时,列对象在wpx字段中存储像素宽度,在wch字段中存储字符宽度,在MDW字段中存储最大数字宽度。

  • ws['!rows']: array of row properties objects as explained later in the docs. :行属性对象的数组,如文档稍后所述。Each row object encodes properties including row height and visibility.每个行对象编码属性,包括行高和可见性。

  • ws['!merges']: array of range objects corresponding to the merged cells in the worksheet. :与工作表中的合并单元格相对应的范围对象数组。Plain text formats do not support merge cells. 纯文本格式不支持合并单元格。CSV export will write all cells in the merge range if they exist, so be sure that only the first cell (upper-left) in the range is set.CSV导出将写入合并区域中的所有单元格(如果存在),因此请确保仅设置该区域中的第一个单元格(左上角)。

  • ws['!outline']: configure how outlines should behave. :配置轮廓的行为方式。Options default to the default settings in Excel 2019:选项默认为Excel 2019中的默认设置:

keyExcel featureExcel功能default默认值
aboveUncheck "Summary rows below detail"取消选中“详细信息下方的摘要行”false
leftUncheck "Summary rows to the right of detail"取消选中“细节右侧的摘要行”false
  • ws['!protect']: object of write sheet protection properties. :写入工作表保护属性的对象。The password key specifies the password for formats that support password-protected sheets (XLSX/XLSB/XLS). password键指定支持密码保护工作表(XLSX/XLSB/XLS)的格式的密码。The writer uses the XOR obfuscation method. 作者使用异或模糊处理方法。The following keys control the sheet protection -- set to false to enable a feature when sheet is locked or set to true to disable a feature:以下键控制板材保护——设置为false以在板材锁定时启用功能,或设置为true以禁用功能:
Worksheet Protection Details工作表保护详细信息 (click to show)
keyfeature功能 (true=disabled / false=enabled)default默认值
selectLockedCellsSelect locked cells选择锁定的单元格enabled
selectUnlockedCellsSelect unlocked cells选择未锁定的单元格enabled
formatCellsFormat cells设置单元格格式disabled
formatColumnsFormat columns设置列格式disabled
formatRowsFormat rows设置行格式disabled
insertColumnsInsert columns插入列disabled
insertRowsInsert rowsdisabled
insertHyperlinksInsert hyperlinksdisabled
deleteColumnsDelete columnsdisabled
deleteRowsDelete rowsdisabled
sortSortdisabled
autoFilterFilterdisabled
pivotTablesUse PivotTable reportsdisabled
objectsEdit objectsenabled
scenariosEdit scenariosenabled
  • ws['!autofilter']: AutoFilter object following the schema::架构后的自动筛选对象:
type AutoFilter = {
ref:string; // A-1 based range representing the AutoFilter table range
}

Other Sheet Types其他工作表类型

Chartsheet Object图表工作表对象

Chartsheets are represented as standard sheets. 图表工作表表示为标准工作表。They are distinguished with the !type property set to "chart".它们通过!type属性设置为"chart"来彰显区分。

The underlying data and !ref refer to the cached data in the chartsheet. 底层数据和!ref指图表中的缓存数据。The first row of the chartsheet is the underlying header.图表工作表的第一行是底层标题。

Macrosheet Object宏表对象

Macrosheets are represented as standard sheets. 宏表表示为标准工作表。They are distinguished with the !type property set to "macro".它们通过!type属性设置为"macro"来区分彰显。

Dialogsheet Object对话框工作表对象

Dialogsheets are represented as standard sheets. 对话框工作表表示为标准工作表。They are distinguished with the !type property set to "dialog".它们通过!type属性设置为"dialog"来区分彰显。