Skip to main content

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},其中CR分别是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. 列由字母指定,从AZ,然后从AAZZ,再到AAASome sample values, along with SheetJS column indices, are listed:列出了一些示例值以及SheetJS列索引:

OrdinalA1 NameSheetJS
FirstA0
SecondB1
26thZ25
27thAA26
702stZZ701
703rdAAA702
16384thXFD16383

Rows are specified with numbers, starting from 1 for the first row. 行由数字指定,第一行从1开始。SheetJS APIs that take row indices start from 0 (ECMAScript convention).采用行索引的SheetJS API从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个单元格:

ABCDE
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单元格范围。