3
3
Deno is a runtime capable of running JS code including this library. There are
4
4
a few different builds and recommended use cases as covered in this demo.
5
5
6
- For user code, [ the ` sheetjs ` module] ( https://deno.land/x/sheetjs ) can be used.
6
+ Due to ongoing stability and sync issues with the Deno registry, scripts should
7
+ use [ the ` unpkg ` CDN build] ( https://unpkg.com/xlsx/xlsx.mjs ) :
8
+
9
+ ``` js
10
+ // @deno-types="https://unpkg.com/xlsx/types/index.d.ts"
11
+ import * as XLSX from ' https://unpkg.com/xlsx/xlsx.mjs' ;
12
+
13
+ /* load the codepage support library for extended support with older formats */
14
+ import * as cptable from ' https://unpkg.com/xlsx/dist/cpexcel.full.mjs' ;
15
+ XLSX .set_cptable (cptable);
16
+ ```
17
+
7
18
8
19
## Reading and Writing Files
9
20
10
21
In general, the command-line flag ` --allow-read ` must be passed to enable file
11
22
reading. The flag ` --allow-write ` must be passed to enable file writing.
12
23
13
- Starting in version 0.18.1, this library will check for the ` Deno ` global and
14
- use ` Deno.readFileSync ` and ` Deno.writeFileSync ` behind the scenes.
15
-
16
- For older versions, the API functions must be called from user code.
17
-
18
24
_ Reading a File_
19
25
20
26
``` ts
21
- const filedata = Deno .readFileSync (" test.xlsx" );
22
- const workbook = XLSX .read (filedata , {type: " buffer" });
23
- /* DO SOMETHING WITH workbook HERE */
27
+ const workbook = XLSX .readFile (" test.xlsx" );
24
28
```
25
29
26
30
_ Writing a File_
@@ -30,9 +34,7 @@ Older versions of the library did not properly detect features from Deno, so the
30
34
not handle byte arrays, user code must generate a ` Uint8Array ` first:
31
35
32
36
``` ts
33
- const buf = XLSX .write (workbook , {type: " buffer" , bookType: " xlsb" });
34
- const u8: Uint8Array = new Uint8Array (buf );
35
- Deno .writeFileSync (" test.xlsb" , u8 );
37
+ XLSX .writeFile (workbook , " test.xlsb" );
36
38
```
37
39
38
40
## Demos
@@ -60,8 +62,8 @@ accepts the `XLSX` module as an argument.
60
62
- ` x ` imports the ESM build without the codepage library:
61
63
62
64
``` ts
63
- // @deno-types="https://deno.land/x/sheetjs /types/index.d.ts"
64
- import * as XLSX from ' https://deno.land/x/sheetjs /xlsx.mjs' ;
65
+ // @deno-types="https://unpkg.com/xlsx /types/index.d.ts"
66
+ import * as XLSX from ' https://unpkg.com/xlsx /xlsx.mjs' ;
65
67
```
66
68
67
69
- ` mjs ` imports the ESM build and the associated codepage library:
@@ -73,12 +75,6 @@ import * as cptable from '../../dist/cptable.full.mjs';
73
75
XLSX .set_cptable (cptable );
74
76
```
75
77
76
- - ` jspm ` imports the browser standalone script using JSPM:
77
-
78
- ``` ts
79
- import * as XLSX from ' https://jspm.dev/npm:xlsx!cjs' ;
80
- ```
81
-
82
78
- ` node ` uses the node compatibility layer:
83
79
84
80
``` ts
0 commit comments