Addresses and Ranges地址和范围
Each cell in a worksheet has a unique address which specifies the row and the column that include the cell.工作表中的每个单元格都有一个唯一的地址,用于指定包含该单元格的行和列。
Basic Concepts基本概念
Rows行
Spreadsheet applications typically display ordinal row numbers, where 电子表格应用程序通常显示序号,其中1
is the first row, 2
is the second row, etc. The numbering starts at 1
.1
是第一行,2
是第二行等。编号从1
开始。
SheetJS follows JavaScript counting conventions, where SheetJS遵循JavaScript计数约定,其中0
is the first row, 1
is the second row, etc. 0
是第一行,1
是第二行,依此类推。The numbering starts at 编号从0
.0
开始。
The following table lists some example row labels:下表列出了一些行标签示例:
SheetJS | ||
---|---|---|
First | 1 | 0 |
Second | 2 | 1 |
26th | 26 | 25 |
420th | 420 | 419 |
7262nd | 7262 | 7261 |
1048576th | 1048576 | 1048575 |
Columns列
Spreadsheet applications typically use letters to represent columns.电子表格应用程序通常使用字母来表示列。
The first column is 第一列为A
, the second column is B
, and the 26th column is Z
. A
,第二列为B
,第二十六列为Z
。After 在Z
, the next column is AA
and counting continues through AZ
. Z
之后,下一列是AA
,并且通过AZ
继续计数。 After AZ
, the count continues with BA
. After ZZ
, the count continues with AAA
.AZ
之后,BA
继续计数。ZZ
之后,AAA
继续计数。
Some sample values, along with SheetJS column indices, are listed below:下面列出了一些示例值以及SheetJS列索引:
Ordinal | Column Label | SheetJS |
---|---|---|
First | A | 0 |
Second | B | 1 |
26th | Z | 25 |
27th | AA | 26 |
420th | PD | 419 |
702nd | ZZ | 701 |
703rd | AAA | 702 |
7262nd | JSH | 7261 |
16384th | XFD | 16383 |
Cell Addresses单元格地址
A1-StyleA1样式
A1-Style is the default address style in Lotus 1-2-3 and Excel.A1样式是Lotus 1-2-3和Excel中的默认地址样式。
A cell address is the concatenation of column label and row label.单元格地址是列标签和行标签的串联。
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
)C4
,连接第三列标签(C
)和第四列标签(4
)
SheetJS Cell AddressSheetJS单元格地址
Cell address objects are stored as 单元地址对象存储为{c:C, r:R}
where C
and R
are 0-indexed column and row numbers, respectively. {c:C, r:R}
,其中C
和R
分别是0索引的列和行号。 For example, the cell address 例如,单元地址B5
is represented by the object {c:1, r:4}
.B5
由对象{c:1, r:4}
表示。
Cell Ranges单元格范围
A1-StyleA1样式
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:"C2:D4"
包括下表中的6个绿色单元格:
A | B | C | D | E | |
---|---|---|---|---|---|
1 | |||||
2 | |||||
3 | |||||
4 | |||||
5 |
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.C:D
表示第三列和第四列。
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.2:4
表示第二行/第三行/第四行。
SheetJS RangeSheetJS范围
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. {s:S, e:E}
,其中S
是该范围中的第一个单元格,E
是最后一个单元格。范围包括在内。For example, the range 例如,范围A3:B7
is represented by the object {s:{c:0, r:2}, e:{c:1, r:6}}
.A3:B7
由对象{s:{c:0, r:2}, e:{c:1, r:6}}
表示。
Column and Row Ranges列和行范围
A column range (spanning every row) is represented with the starting row 列范围(跨越每一行)由起始行0
and the ending row 1048575
:0
和结束行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
A row range (spanning every column) is represented with the starting col 行范围(跨越每列)由起始列0
and the ending col 16383
:0
和结束列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列名
Get the SheetJS index from an A1-Style column从A1样式列获取SheetJS索引
var col_index = XLSX.utils.decode_col("D");
The argument is expected to be a string representing a column.参数应为表示列的字符串。
Get the A1-Style column string from a SheetJS index从SheetJS索引中获取A1样式列字符串
var col_name = XLSX.utils.encode_col(3);
The argument is expected to be a SheetJS column (non-negative integer).参数应为SheetJS列(非负整数)。
Row Names行名称
Get the SheetJS index from an A1-Style row从A1样式行获取SheetJS索引
var row_index = XLSX.utils.decode_row("4");
The argument is expected to be a string representing a row.参数应为表示一行的字符串。
Get the A1-Style row string from a SheetJS index从SheetJS索引中获取A1样式行字符串
var row_name = XLSX.utils.encode_row(3);
The argument is expected to be a SheetJS column (non-negative integer).参数应为SheetJS列(非负整数)。
Cell Addresses单元格地址
Generate a SheetJS cell address from an A1-Style address string从A1样式地址字符串生成SheetJS单元格地址
var address = XLSX.utils.decode_cell("A2");
The argument is expected to be a string representing a single cell address.参数应为表示单个单元格地址的字符串。
Generate an A1-Style address string from a SheetJS cell address从SheetJS单元格地址生成A1样式地址字符串
var a1_addr = XLSX.utils.encode_cell({r:1, c:0});
The argument is expected to be a SheetJS cell address参数应为SheetJS单元格地址
Cell Ranges单元格范围
Generate a SheetJS cell range from an A1-Style range string从A1样式范围字符串生成SheetJS单元格范围
var range = XLSX.utils.decode_range("A1: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")
XLSX.utils.decode_range("D3")
与XLSX.utils.decode_range("D3:D3")
相同
Generate an A1-Style address string from a SheetJS cell address从SheetJS单元格地址生成A1样式地址字符串
var a1_range = XLSX.utils.encode_range({ s: { c: 0, r: 0 }, e: { c: 3, r: 2 } });
The argument is expected to be a SheetJS cell range.参数应为SheetJS单元格范围。