Addresses and Ranges地址和范围
The "Common Spreadsheet Format" (CSF) is the object model used by SheetJS.“通用电子表格格式”(CSF)是SheetJS使用的对象模型。
Cell Addresses单元格地址
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单元格范围
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. {s:S, e:E}
,其中S
是范围中的第一个单元格,E
是范围中的最后一个单元格。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}}
.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
Common Spreadsheet Address Styles常用电子表格地址样式
A1-Style
A1-style is the default address style in Lotus 1-2-3 and Excel.A1样式是Lotus 1-2-3和Excel中的默认地址样式。
Columns are specified with letters, counting from 列由字母指定,从A
to Z
, then AA
to ZZ
, then AAA
. A
到Z
,然后从AA
到ZZ
,再到AAA
。Some sample values, along with SheetJS column indices, are listed:列出了一些示例值以及SheetJS列索引:
Ordinal | A1 Name | SheetJS |
---|---|---|
First | A | 0 |
Second | B | 1 |
26th | Z | 25 |
27th | AA | 26 |
702st | ZZ | 701 |
703rd | AAA | 702 |
16384th | XFD | 16383 |
Rows are specified with numbers, starting from 行由数字指定,第一行从1
for the first row. 1
开始。SheetJS APIs that take row indices start from 采用行索引的SheetJS API从0
(ECMAScript convention).0
开始(ECMAScript约定)。
A cell address is the concatenation of column text and row number. 单元格地址是列文本和行号的串联。For example, the cell in the third column and fourth row is "C4".例如,第三列和第四行中的单元格是“C4”。
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 6 cells marked with ▒ in the table below:"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
表示第二行/第三行/第四行。
A1 UtilitiesA1实用工具
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单元格范围。