Skip to main content

地址和范围

工作表中的每个单元格都有一个唯一的地址,用于指定包含该单元格的行和列。

¥Each cell in a worksheet has a unique address which specifies the row and the column that include the cell.

基本概念

¥Basic Concepts

行数

¥Rows

电子表格应用通常显示序号行号,其中 1 是第一行,2 是第二行,依此类推。编号从 1 开始。

¥Spreadsheet applications typically display ordinal row numbers, where 1 is the first row, 2 is the second row, etc. The numbering starts at 1.

SheetJS 遵循 JavaScript 计数约定,其中 0 是第一行,1 是第二行,依此类推。编号从 0 开始。

¥SheetJS follows JavaScript counting conventions, where 0 is the first row, 1 is the second row, etc. The numbering starts at 0.

下表列出了一些示例行标签:

¥The following table lists some example row labels:

序数行标签SheetJS
First10
Second21
26 日2625
第 420 期420419
第 7262 号72627261
1048576 号10485761048575

¥Columns

电子表格应用通常使用字母来表示列。

¥Spreadsheet applications typically use letters to represent columns.

第一列是 A,第二列是 B,第 26 列是 ZZ 之后,下一列是 AA,并继续计数到 AZAZ 之后,计数从 BA 继续。ZZ 之后,计数从 AAA 继续。

¥The first column is A, the second column is B, and the 26th column is Z. After Z, the next column is AA and counting continues through AZ. After AZ, the count continues with BA. After ZZ, the count continues with AAA.

下面列出了一些示例值以及 SheetJS 列索引:

¥Some sample values, along with SheetJS column indices, are listed below:

序数列标签SheetJS
FirstA0
SecondB1
26 日Z25
27 日AA26
第 420 期PD419
702 号ZZ701
第 703 期AAA702
第 7262 号JSH7261
16384 号XFD16383

单元格地址

¥Cell Addresses

A1-Style

A1-Style 是 Lotus 1-2-3 和 Excel 中的默认地址样式。

¥A1-Style is the default address style in Lotus 1-2-3 and Excel.

单元格地址是列标签和行标签的串联。

¥A cell address is the concatenation of column label and row label.

例如,第三列第四行的单元格是 C4,连接第三列标签(C)和第四行标签(4

¥For example, the cell in the third column and fourth row is C4, concatenating the third column label (C) and the fourth row label (4)

SheetJS 单元格地址

¥SheetJS Cell Address

单元格地址对象存储为 {c:C, r:R},其中 CR 分别是 0 索引的列号和行号。例如,单元格地址 B5 由对象 {c:1, r:4} 表示。

¥Cell address objects are stored as {c:C, r:R} where C and R are 0-indexed column and row numbers, respectively. For example, the cell address B5 is represented by the object {c:1, r:4}.

单元格范围

¥Cell Ranges

A1-Style

单元格范围表示为该范围的左上角单元格,后跟 :,最后是该范围右下角单元格。例如,范围 "C2:D4" 包括下表中的 6 个绿色单元格:

¥A cell range is represented as the top-left cell of the range, followed by :, followed by the bottom-right cell of the range. For example, the range "C2:D4" includes the 6 green cells in the following table:

ABCDE
1
2
3
4
5

列范围由最左侧的列、:、最右侧的列表示。例如,范围 C:D 代表第三列和第四列。

¥A column range is represented by the left-most column, followed by :, followed by the right-most column. For example, the range C:D represents the third and fourth columns.

行范围由最顶部的行、后面的 : 和最底部的列表示。例如,2:4 代表第二/第三/第四行。

¥A row range is represented by the top-most row, followed by :, followed by the bottom-most column. For example, 2:4 represents the second/third/fourth rows.

SheetJS 范围

¥SheetJS Range

单元格范围对象存储为 {s:S, e:E},其中 S 是该范围中的第一个单元格,E 是最后一个单元格。范围包括在内。例如,范围 A3:B7 由对象 {s:{c:0, r:2}, e:{c:1, r:6}} 表示。

¥Cell range objects are stored as {s:S, e:E} where S is the first cell and E is the last cell in the range. The ranges are inclusive. For example, the range A3:B7 is represented by the object {s:{c:0, r:2}, e:{c:1, r:6}}.

列和行范围

¥Column and Row Ranges

列范围(跨越每一行)用起始行 0 和结束行 1048575 表示:

¥A column range (spanning every row) is represented with the starting row 0 and the ending row 1048575:

{ s: { c: 0, r: 0 }, e: { c: 0, r: 1048575 } } // A:A
{ s: { c: 1, r: 0 }, e: { c: 2, r: 1048575 } } // B:C

行范围(跨越每一列)用起始列 0 和结束列 16383 表示:

¥A row range (spanning every column) is represented with the starting col 0 and the ending col 16383:

{ s: { c: 0, r: 0 }, e: { c: 16383, r: 0 } } // 1:1
{ s: { c: 0, r: 1 }, e: { c: 16383, r: 2 } } // 2:3

实用工具

¥Utilities

列名称

¥Column Names

从 A1 样式列获取 SheetJS 索引

¥Get the SheetJS index from an A1-Style column

var col_index = XLSX.utils.decode_col("D");

该参数应该是表示列的字符串。

¥The argument is expected to be a string representing a column.

从 SheetJS 索引获取 A1 样式列字符串

¥Get the A1-Style column string from a SheetJS index

var col_name = XLSX.utils.encode_col(3);

该参数应为 SheetJS 列(非负整数)。

¥The argument is expected to be a SheetJS column (non-negative integer).

行名称

¥Row Names

从 A1 样式行获取 SheetJS 索引

¥Get the SheetJS index from an A1-Style row

var row_index = XLSX.utils.decode_row("4");

该参数应为表示行的字符串。

¥The argument is expected to be a string representing a row.

从 SheetJS 索引获取 A1 样式行字符串

¥Get the A1-Style row string from a SheetJS index

var row_name = XLSX.utils.encode_row(3);

该参数应为 SheetJS 列(非负整数)。

¥The argument is expected to be a SheetJS column (non-negative integer).

单元格地址

¥Cell Addresses

从 A1 样式地址字符串生成 SheetJS 单元格地址

¥Generate a SheetJS cell address from an A1-Style address string

var address = XLSX.utils.decode_cell("A2");

该参数应为表示单个单元格地址的字符串。

¥The argument is expected to be a string representing a single cell address.

从 SheetJS 单元格地址生成 A1 样式的地址字符串

¥Generate an A1-Style address string from a SheetJS cell address

var a1_addr = XLSX.utils.encode_cell({r:1, c:0});

该参数应为 SheetJS 单元格地址

¥The argument is expected to be a SheetJS cell address

单元格范围

¥Cell Ranges

从 A1 样式范围字符串生成 SheetJS 单元格范围

¥Generate a SheetJS cell range from an A1-Style range string

var range = XLSX.utils.decode_range("A1:D3");

该参数应为表示范围或单个单元格地址的字符串。单个单元格地址被解释为单个单元格范围,因此 XLSX.utils.decode_range("D3")XLSX.utils.decode_range("D3:D3") 相同

¥The argument is expected to be a string representing a range or a single cell address. The single cell address is interpreted as a single cell range, so XLSX.utils.decode_range("D3") is the same as XLSX.utils.decode_range("D3:D3")

从 SheetJS 单元格地址生成 A1 样式的地址字符串

¥Generate an A1-Style address string from a SheetJS cell address

var a1_range = XLSX.utils.encode_range({ s: { c: 0, r: 0 }, e: { c: 3, r: 2 } });

该参数预计是 SheetJS 单元格范围。

¥The argument is expected to be a SheetJS cell range.