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