2022-02-04 05:29:01 +00:00
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
### Installation
|
2017-03-20 09:02:25 +00:00
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
**Standalone Browser Scripts**
|
|
|
|
|
2022-02-05 13:59:25 +00:00
|
|
|
The complete browser standalone build is saved to `dist/xlsx.full.min.js` and
|
|
|
|
can be directly added to a page with a `script` tag:
|
2017-03-20 09:02:25 +00:00
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
```html
|
|
|
|
<script lang="javascript" src="dist/xlsx.full.min.js"></script>
|
2017-03-20 09:02:25 +00:00
|
|
|
```
|
|
|
|
|
2017-09-24 23:40:09 +00:00
|
|
|
<details>
|
|
|
|
<summary><b>CDN Availability</b> (click to show)</summary>
|
|
|
|
|
2018-03-19 21:42:55 +00:00
|
|
|
| CDN | URL |
|
|
|
|
|-----------:|:-------------------------------------------|
|
|
|
|
| `unpkg` | <https://unpkg.com/xlsx/> |
|
|
|
|
| `jsDelivr` | <https://jsdelivr.com/package/npm/xlsx> |
|
2021-09-22 06:45:08 +00:00
|
|
|
| `CDNjs` | <https://cdnjs.com/libraries/xlsx> |
|
2018-03-19 21:42:55 +00:00
|
|
|
| `packd` | <https://bundle.run/xlsx@latest?name=XLSX> |
|
2017-09-24 23:40:09 +00:00
|
|
|
|
2022-02-05 13:59:25 +00:00
|
|
|
For example, `unpkg` makes the latest version available at:
|
2017-09-24 23:40:09 +00:00
|
|
|
|
|
|
|
```html
|
|
|
|
<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
|
|
|
|
```
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
2022-02-04 05:29:01 +00:00
|
|
|
<details>
|
2022-02-05 13:59:25 +00:00
|
|
|
<summary><b>Browser builds</b> (click to show)</summary>
|
2022-02-04 05:29:01 +00:00
|
|
|
|
|
|
|
The complete single-file version is generated at `dist/xlsx.full.min.js`
|
|
|
|
|
|
|
|
A slimmer build is generated at `dist/xlsx.mini.min.js`. Compared to full build:
|
|
|
|
- codepage library skipped (no support for XLS encodings)
|
|
|
|
- XLSX compression option not currently available
|
|
|
|
- no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003
|
|
|
|
- node stream utils removed
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
2022-02-05 13:59:25 +00:00
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
With [bower](https://bower.io/search/?q=js-xlsx):
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ bower install js-xlsx
|
|
|
|
```
|
|
|
|
|
2022-02-14 01:28:13 +00:00
|
|
|
**ECMAScript Modules**
|
|
|
|
|
|
|
|
The ECMAScript Module build is saved to `xlsx.mjs` and can be directly added to
|
|
|
|
a page with a `script` tag using `type=module`:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script type="module">
|
|
|
|
import { read, writeFileXLSX } from "./xlsx.mjs";
|
|
|
|
|
|
|
|
/* load the codepage support library for extended support with older formats */
|
|
|
|
import { set_cptable } from "./xlsx.mjs";
|
|
|
|
import * as cptable from './dist/cpexcel.full.mjs';
|
|
|
|
set_cptable(cptable);
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
|
|
|
The [npm package](https://www.npmjs.org/package/xlsx) also exposes the module
|
|
|
|
with the `module` parameter, supported in Angular and other projects:
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import { read, writeFileXLSX } from "xlsx";
|
|
|
|
|
|
|
|
/* load the codepage support library for extended support with older formats */
|
|
|
|
import { set_cptable } from "xlsx";
|
|
|
|
import * as cptable from 'xlsx/dist/cpexcel.full.mjs';
|
|
|
|
set_cptable(cptable);
|
|
|
|
```
|
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
**Deno**
|
|
|
|
|
2022-02-13 09:35:34 +00:00
|
|
|
The [`sheetjs`](https://deno.land/x/sheetjs) package is hosted by Deno:
|
2022-02-12 06:31:47 +00:00
|
|
|
|
|
|
|
```ts
|
2022-02-13 09:35:34 +00:00
|
|
|
// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts"
|
2022-02-12 06:31:47 +00:00
|
|
|
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
|
2022-02-13 09:35:34 +00:00
|
|
|
|
|
|
|
/* load the codepage support library for extended support with older formats */
|
|
|
|
import * as cptable from 'https://deno.land/x/sheetjs/dist/cpexcel.full.mjs';
|
|
|
|
XLSX.set_cptable(cptable);
|
2022-02-12 06:31:47 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
**NodeJS**
|
|
|
|
|
2022-02-05 13:59:25 +00:00
|
|
|
With [npm](https://www.npmjs.org/package/xlsx):
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ npm install xlsx
|
|
|
|
```
|
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
By default, the module supports `require`:
|
2022-02-05 13:59:25 +00:00
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
```js
|
|
|
|
var XLSX = require("xlsx");
|
2022-02-05 13:59:25 +00:00
|
|
|
```
|
|
|
|
|
2022-02-12 06:31:47 +00:00
|
|
|
The module also ships with `xlsx.mjs` for use with `import`:
|
|
|
|
|
|
|
|
```js
|
|
|
|
import * as XLSX from 'xlsx/xlsx.mjs';
|
|
|
|
|
|
|
|
/* load 'fs' for readFile and writeFile support */
|
|
|
|
import * as fs from 'fs';
|
|
|
|
XLSX.set_fs(fs);
|
|
|
|
|
|
|
|
/* load the codepage support library for extended support with older formats */
|
|
|
|
import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
|
|
|
|
XLSX.set_cptable(cpexcel);
|
|
|
|
```
|
|
|
|
|
2022-02-13 09:35:34 +00:00
|
|
|
**Photoshop and InDesign**
|
2022-02-12 06:31:47 +00:00
|
|
|
|
2022-02-05 13:59:25 +00:00
|
|
|
`dist/xlsx.extendscript.js` is an ExtendScript build for Photoshop and InDesign
|
|
|
|
that is included in the `npm` package. It can be directly referenced with a
|
|
|
|
`#include` directive:
|
|
|
|
|
|
|
|
```extendscript
|
|
|
|
#include "xlsx.extendscript.js"
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2022-02-04 05:29:01 +00:00
|
|
|
<details>
|
2022-02-05 13:59:25 +00:00
|
|
|
<summary><b>Internet Explorer and ECMAScript 3 Compatibility</b> (click to show)</summary>
|
2022-02-04 05:29:01 +00:00
|
|
|
|
|
|
|
For broad compatibility with JavaScript engines, the library is written using
|
|
|
|
ECMAScript 3 language dialect as well as some ES5 features like `Array#forEach`.
|
|
|
|
Older browsers require shims to provide missing functions.
|
|
|
|
|
|
|
|
To use the shim, add the shim before the script tag that loads `xlsx.js`:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<!-- add the shim first -->
|
|
|
|
<script type="text/javascript" src="shim.min.js"></script>
|
|
|
|
<!-- after the shim is referenced, add the library -->
|
|
|
|
<script type="text/javascript" src="xlsx.full.min.js"></script>
|
|
|
|
```
|
|
|
|
|
|
|
|
The script also includes `IE_LoadFile` and `IE_SaveFile` for loading and saving
|
|
|
|
files in Internet Explorer versions 6-9. The `xlsx.extendscript.js` script
|
|
|
|
bundles the shim in a format suitable for Photoshop and other Adobe products.
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|