NodeJS
Tarballs are available on https://cdn.sheetjs.com.Tarballs可在https://cdn.sheetjs.com上获得。
https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
Installation安装
Tarballs can be directly installed using a package manager:Tarball可以使用软件包管理器直接安装:
- npm
- pnpm
- Yarn
$ npm install --save https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
$ pnpm install --save https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
$ yarn add --save https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
Vendoring供应商
For general stability, "vendoring" modules is the recommended approach:对于一般稳定性,“供应商”模块是推荐的方法:
xlsx-0.18.9.tgz) for the desired version. xlsx-0.18.9.tgz)。2) Create a 在项目的根目录下创建一个vendor subdirectory at the root of your project and move the tarball to that folder. vendor子目录,并将tarball移动到该文件夹中。Add it to your project repository.将其添加到项目存储库中。
3) Install the tarball using a package manager:使用软件包管理器安装tarball:
- npm
- pnpm
- Yarn
$ npm install --save file:vendor/xlsx-0.18.9.tgz
$ pnpm install --save file:vendor/xlsx-0.18.9.tgz
$ yarn add --save file:vendor/xlsx-0.18.9.tgz
The package will be installed and accessible as 该软件包将作为xlsx.xlsx安装和访问。
Usage用法
CommonJS require
By default, the module supports 默认情况下,该模块支持require and it will automatically add support for streams and filesystem access:require,并将自动添加对流和文件系统访问的支持:
var XLSX = require("xlsx");
ESM import
The module also ships with 该模块还附带xlsx.mjs for use with import. xlsx.mjs,用于导入。The mjs version does not automatically load native node modules, so they must be added manually:mjs版本不会自动加载本机节点模块,因此必须手动添加这些模块:
import * as XLSX from 'xlsx/xlsx.mjs';
/* load 'fs' for readFile and writeFile support */
import * as fs from 'fs';
XLSX.set_fs(fs);
/* load 'stream' for stream support */
import { Readable } from 'stream';
XLSX.stream.set_readable(Readable);
/* load the codepage support library for extended support with older formats */
import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
XLSX.set_cptable(cpexcel);