API 参考
本节列出了库中定义的函数。
¥This section lists the functions defined in the library.
"SheetJS 数据模型" 部分涵盖电子表格功能。
¥The "SheetJS Data Model" section covers spreadsheet features.
API 函数主要关注数据表示之间的转换。
¥The API functions primarily focus on conversions between data representations.
库访问
¥Library access
使用 "独立式" 脚本,XLSX 被添加到 window 或其他 global 对象。
¥Using the "Standalone" scripts,
XLSX is added to the window or other global object.
使用 "NodeJS" 模块,XLSX 变量引用 CommonJS 导出:
¥Using the "NodeJS" module, the
XLSX variable refers to the CommonJS export:
var XLSX = require("xlsx");
使用 一个框架,XLSX 变量引用 glob 导入:
¥Using a framework, the XLSX
variable refers to the glob import:
import * as XLSX from "xlsx";
解析函数
¥Parsing functions
XLSX.read(data, read_opts) 尝试解析 data。
¥XLSX.read(data, read_opts) attempts to parse data.
XLSX.readFile(filename, read_opts) 尝试读取 filename 并解析。
¥XLSX.readFile(filename, read_opts) attempts to read filename and parse.
解析选项在 解析选项 部分中描述。
¥Parse options are described in the Parsing Options section.
编写函数
¥Writing functions
XLSX.write(wb, write_opts) 尝试编写工作簿 wb。
¥XLSX.write(wb, write_opts) attempts to write the workbook wb.
XLSX.writeXLSX(wb, write_opts) 尝试以 XLSX 格式编写工作簿。
¥XLSX.writeXLSX(wb, write_opts) attempts to write the workbook in XLSX format.
XLSX.writeFile(wb, filename, write_opts) 尝试将 wb 写入 filename。在基于浏览器的环境中,它将尝试强制客户端下载。
¥XLSX.writeFile(wb, filename, write_opts) attempts to write wb to filename.
In browser-based environments, it will attempt to force a client-side download.
XLSX.writeFileXLSX(wb, filename, write_opts) 尝试写入 XLSX 文件。
¥XLSX.writeFileXLSX(wb, filename, write_opts) attempts to write an XLSX file.
XLSX.writeFileAsync(filename, wb, o, cb) 尝试将 wb 写入 filename。如果省略 o,编写器将使用第三个参数作为回调。
¥XLSX.writeFileAsync(filename, wb, o, cb) attempts to write wb to filename.
If o is omitted, the writer will use the third argument as the callback.
写入选项在 写作选项 部分中描述。
¥Write options are described in the Writing Options section.
实用工具
¥Utilities
实用程序在 XLSX.utils 对象中可用。
¥Utilities are available in the XLSX.utils object.
这些方法包含在专门的页面中:
¥The methods are covered in dedicated pages:
单元格和单元格地址操作:
¥Cell and cell address manipulation:
-
encode_row / decode_row在 0 索引行和 1 索引行之间转换。¥
encode_row / decode_rowconverts between 0-indexed rows and 1-indexed rows. -
encode_col / decode_col在 0 索引列和列名之间进行转换。¥
encode_col / decode_colconverts between 0-indexed columns and column names. -
encode_cell / decode_cell转换单元格地址。¥
encode_cell / decode_cellconverts cell addresses. -
encode_range / decode_range转换单元格范围。¥
encode_range / decode_rangeconverts cell ranges.
¥"Arrays of Data" section of "Utility Functions"
导入数据:
¥Importing Data:
-
aoa_to_sheet将 JS 数据数组的数组转换为工作表。¥
aoa_to_sheetconverts an array of arrays of JS data to a worksheet. -
json_to_sheet将 JS 对象数组转换为工作表。¥
json_to_sheetconverts an array of JS objects to a worksheet. -
sheet_add_aoa将 JS 数据数组的数组添加到现有工作表中。¥
sheet_add_aoaadds an array of arrays of JS data to an existing worksheet. -
sheet_add_json将 JS 对象数组添加到现有工作表中。¥
sheet_add_jsonadds an array of JS objects to an existing worksheet.
导出数据:
¥Exporting Data:
-
sheet_to_json将工作表对象转换为 JSON 对象数组。¥
sheet_to_jsonconverts a worksheet object to an array of JSON objects.
¥"HTML" section of "Utility Functions"
从 HTML 读取:
¥Reading from HTML:
-
table_to_sheet将 DOM TABLE 元素转换为工作表。¥
table_to_sheetconverts a DOM TABLE element to a worksheet. -
table_to_book将 DOM TABLE 元素转换为工作表。¥
table_to_bookconverts a DOM TABLE element to a worksheet. -
sheet_add_dom将 DOM TABLE 元素中的数据添加到现有工作表中。¥
sheet_add_domadds data from a DOM TABLE element to an existing worksheet.
编写 HTML:
¥Writing HTML:
-
sheet_to_html生成 HTML 输出。¥
sheet_to_htmlgenerates HTML output.
¥"CSV and Text" section of "Utility Functions"
写入 CSV 和文本:
¥Writing CSV and Text:
-
sheet_to_csv生成分隔符分隔值输出。¥
sheet_to_csvgenerates delimiter-separated-values output. -
sheet_to_txt生成 UTF-16 格式的文本。¥
sheet_to_txtgenerates UTF-16 formatted text.
¥"Array of Formulae" section of "Utility Functions"
导出公式:
¥Exporting Formulae:
-
sheet_to_formulae生成公式或单元格值分配的列表。¥
sheet_to_formulaegenerates a list of formulae or cell value assignments.
¥"Workbook Helpers" section of "Utility Functions"
作业簿操作:
¥Workbook Operations:
-
book_new创建一个工作簿对象¥
book_newcreates a workbook object -
book_append_sheet将工作表添加到工作簿¥
book_append_sheetadds a worksheet to a workbook
杂项
¥Miscellaneous
-
format_cell生成单元格的文本值(使用数字格式)。¥
format_cellgenerates the text value for a cell (using number formats). -
sheet_set_array_formula将数组公式添加到工作表¥
sheet_set_array_formulaadds an array formula to a worksheet
平台特定功能
¥Platform-Specific Functions
NodeJS 流写入函数
¥NodeJS Streaming Write functions
XLSX.stream 包含一组 NodeJS 流的流写入函数:
¥XLSX.stream contains a set of streaming write functions for NodeJS streams:
-
to_csv(sheet, opts)流 CSV 行¥
to_csv(sheet, opts)streams CSV rows -
to_html(sheet, opts)增量式传输 HTML 表¥
to_html(sheet, opts)streams an HTML table incrementally -
to_json(sheet, opts)流 JS 对象(对象模式流)¥
to_json(sheet, opts)streams JS objects (object-mode stream) -
to_xlml(book, opts)逐步传输 SpreadsheetML2003 工作簿¥
to_xlml(book, opts)streams a SpreadsheetML2003 workbook incrementally
流方法在 "流导出" 部分中描述。
¥Stream methods are described in the "Stream Export" section.
ESM 助手
¥ESM Helpers
由于 ESM 实现中存在广泛的不一致,mjs 版本不会导入任何依赖。相反,它们必须手动传递到库:
¥Due to broad inconsistencies in ESM implementations, the mjs build does not
import any dependencies. Instead, they must be manually passed to the library:
XLSX.set_cptable 设置内部 codepage 实例。这为 XLS 或文本解析中的不同语言提供了支持。
¥XLSX.set_cptable sets the internal codepage instance. This provides support
for different languages in XLS or text parsing.
XLSX.set_fs 设置 fs 实例(使用 readFileSync 和 writeFileSync)。这为 XLSX.readFile 和 XLSX.writeFile 提供了 NodeJS ESM 支持。
¥XLSX.set_fs set fs instance (using readFileSync and writeFileSync). This
provides NodeJS ESM support for XLSX.readFile and XLSX.writeFile.
XLSX.utils.set_readable 提供 NodeJS stream.Readable 构造函数。这为流操作提供了 NodeJS ESM 支持。
¥XLSX.utils.set_readable supplies a NodeJS stream.Readable constructor. This
provides NodeJS ESM support for the streaming operations.
ESM 辅助函数在 "NodeJS" 安装部分 中进行了描述
¥ESM helper functions are described in the "NodeJS" Installation section
杂项
¥Miscellaneous
XLSX.version 是库的版本。
¥XLSX.version is the version of the library.
The current version is 0.20.3
XLSX.SSF 是 格式库 的嵌入式版本。
¥XLSX.SSF is an embedded version of the format library.
XLSX.CFB 是 容器库 的嵌入式版本。
¥XLSX.CFB is an embedded version of the container library.