|
|
|
@ -3,24 +3,28 @@
|
|
|
|
|
Deno is a runtime capable of running JS code including this library. There are
|
|
|
|
|
a few different builds and recommended use cases as covered in this demo.
|
|
|
|
|
|
|
|
|
|
For user code, [the `sheetjs` module](https://deno.land/x/sheetjs) can be used.
|
|
|
|
|
Due to ongoing stability and sync issues with the Deno registry, scripts should
|
|
|
|
|
use [the `unpkg` CDN build](https://unpkg.com/xlsx/xlsx.mjs):
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// @deno-types="https://unpkg.com/xlsx/types/index.d.ts"
|
|
|
|
|
import * as XLSX from 'https://unpkg.com/xlsx/xlsx.mjs';
|
|
|
|
|
|
|
|
|
|
/* load the codepage support library for extended support with older formats */
|
|
|
|
|
import * as cptable from 'https://unpkg.com/xlsx/dist/cpexcel.full.mjs';
|
|
|
|
|
XLSX.set_cptable(cptable);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Reading and Writing Files
|
|
|
|
|
|
|
|
|
|
In general, the command-line flag `--allow-read` must be passed to enable file
|
|
|
|
|
reading. The flag `--allow-write` must be passed to enable file writing.
|
|
|
|
|
|
|
|
|
|
Starting in version 0.18.1, this library will check for the `Deno` global and
|
|
|
|
|
use `Deno.readFileSync` and `Deno.writeFileSync` behind the scenes.
|
|
|
|
|
|
|
|
|
|
For older versions, the API functions must be called from user code.
|
|
|
|
|
|
|
|
|
|
_Reading a File_
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
const filedata = Deno.readFileSync("test.xlsx");
|
|
|
|
|
const workbook = XLSX.read(filedata, {type: "buffer"});
|
|
|
|
|
/* DO SOMETHING WITH workbook HERE */
|
|
|
|
|
const workbook = XLSX.readFile("test.xlsx");
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Writing a File_
|
|
|
|
@ -30,9 +34,7 @@ Older versions of the library did not properly detect features from Deno, so the
|
|
|
|
|
not handle byte arrays, user code must generate a `Uint8Array` first:
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
const buf = XLSX.write(workbook, {type: "buffer", bookType: "xlsb"});
|
|
|
|
|
const u8: Uint8Array = new Uint8Array(buf);
|
|
|
|
|
Deno.writeFileSync("test.xlsb", u8);
|
|
|
|
|
XLSX.writeFile(workbook, "test.xlsb");
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Demos
|
|
|
|
@ -60,8 +62,8 @@ accepts the `XLSX` module as an argument.
|
|
|
|
|
- `x` imports the ESM build without the codepage library:
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts"
|
|
|
|
|
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs';
|
|
|
|
|
// @deno-types="https://unpkg.com/xlsx/types/index.d.ts"
|
|
|
|
|
import * as XLSX from 'https://unpkg.com/xlsx/xlsx.mjs';
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- `mjs` imports the ESM build and the associated codepage library:
|
|
|
|
@ -73,12 +75,6 @@ import * as cptable from '../../dist/cptable.full.mjs';
|
|
|
|
|
XLSX.set_cptable(cptable);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- `jspm` imports the browser standalone script using JSPM:
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import * as XLSX from 'https://jspm.dev/npm:xlsx!cjs';
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- `node` uses the node compatibility layer:
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|