Skip to main content

Interface Summary接口摘要

XLSX is the exposed variable in the browser and the exported node variable是浏览器中公开的变量和导出的节点变量

XLSX.version is the version of the library (added by the build script).是库的版本(由生成脚本添加)。

XLSX.SSF is an embedded version of the format library.格式库的嵌入式版本。

XLSX.CFB is an embedded version of the container library.容器库的嵌入式版本。

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写入filenameIn 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写入filenameIf 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 following are described in A1 UtilitiesA1实用程序中描述了以下内容

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.转换单元格范围。

The following are described in the Utility Functions:实用程序函数中描述了以下内容:

Constructing:构造:

  • book_new creates an empty workbook创建空工作簿
  • book_append_sheet adds a worksheet to a workbook将工作表添加到工作簿

Importing:导入:

  • 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对象数组转换为工作表。
  • table_to_sheet converts a DOM TABLE element to a worksheet.将DOM表元素转换为工作表。
  • 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对象数组添加到现有工作表中。
  • sheet_add_dom adds data from a DOM TABLE element to an existing worksheet.将DOM表元素中的数据添加到现有工作表中。

Exporting:导出:

  • sheet_to_json converts a worksheet object to an array of JSON objects.将工作表对象转换为JSON对象数组。
  • sheet_to_csv generates delimiter-separated-values output.生成分隔符分隔的值输出。
  • sheet_to_txt generates UTF16 formatted text.生成UTF16格式的文本。
  • sheet_to_html generates HTML output.生成HTML输出。
  • sheet_to_formulae generates a list of the formulae (with value fallbacks).生成公式列表(具有值回退)。

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 functionsNode.js流写函数

XLSX.stream contains a set of streaming write functions for NodeJS streams:包含一组用于Node.js流的流写入函数:

  • 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)streams JS对象(对象模式流)

ESM HelpersESM助手

Due to broad inconsistencies in ESM implementations, the mjs build does not import any dependencies. 由于ESM实现中存在广泛的不一致性,mjs构建没有导入任何依赖项。Instead, they must be manually passed to the library:相反,它们必须手动传递到库:

XLSX.set_cptable sets the internal codepage instance. 设置内部codepage实例。This provides support for different language encodings.这为不同的语言编码提供了支持。

XLSX.set_fs set fs instance (using readFileSync and writeFileSync). 设置fs实例(使用readFileSyncwriteFileSync)。This provides NodeJS ESM support for XLSX.readFile and XLSX.writeFile.这为Node.js ESM提供了对XLSX.readFileXLSX.writeFile的支持。

XLSX.utils.set_readable supplies a NodeJS stream.Readable constructor. 提供Node.js stream.Readable构造函数。This provides NodeJS ESM support for the streaming operations.