esm support and deno demo

This commit is contained in:
SheetJS 2022-02-12 01:31:47 -05:00
parent dd6bb022e2
commit 88225f5fd5
27 changed files with 1869 additions and 23385 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ tmp
*.[oO][dD][sS]
*.[fF][oO][dD][sS]
*.[xX][mM][lL]
*.[xX][lL][mM][lL]
*.[uU][oO][sS]
*.[wW][kKqQbB][S1234567890]
*.[qQ][pP][wW]

View File

@ -35,6 +35,7 @@ tooltips
Browserify
CDNjs
CommonJS
Deno
Ethercalc
ExtendScript
IndexedDB

View File

@ -11,8 +11,6 @@ MINITGT=xlsx.mini.js
MINIFLOW=xlsx.mini.flow.js
MINIDEPS=$(shell cat mini.lst)
NODESMTGT=xlsx.esm.mjs
NODESMDEPS=$(shell cat misc/esm.lst)
ESMJSTGT=xlsx.mjs
ESMJSDEPS=$(shell cat misc/mjs.lst)
@ -31,7 +29,7 @@ CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar
## Main Targets
.PHONY: all
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT) $(NODESMTGT) $(ESMJSTGT) ## Build library and auxiliary scripts
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT) $(ESMJSTGT) ## Build library and auxiliary scripts
$(FLOWTGTS): %.js : %.flow.js
node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@
@ -42,9 +40,6 @@ $(FLOWTARGET): $(DEPS)
$(MINIFLOW): $(MINIDEPS)
cat $^ | tr -d '\15\32' > $@
$(NODESMTGT): $(NODESMDEPS)
cat $^ | tr -d '\15\32' > $@
$(ESMJSTGT): $(ESMJSDEPS)
cat $^ | tr -d '\15\32' > $@

View File

@ -118,6 +118,8 @@ port calculations to web apps; automate common spreadsheet tasks, and much more!
### Installation
**Standalone Browser Scripts**
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:
@ -167,18 +169,50 @@ be configured to remove support with `resolve.alias`:
</details>
With [bower](https://bower.io/search/?q=js-xlsx):
```bash
$ bower install js-xlsx
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is available on deno:
```ts
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
```
**NodeJS**
With [npm](https://www.npmjs.org/package/xlsx):
```bash
$ npm install xlsx
```
With [bower](https://bower.io/search/?q=js-xlsx):
By default, the module supports `require`:
```bash
$ bower install js-xlsx
```js
var XLSX = require("xlsx");
```
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);
```
**PhotoShop and InDesign**
`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:
@ -1650,7 +1684,9 @@ data grid for previewing and modifying structured data in the web browser. The
[`react-data-grid`](https://npm.im/react-data-grid) is a data grid tailored for
react. It expects two properties: `rows` of data objects and `columns` which
describe the columns. For the purposes of massaging the data to fit the react
data grid API it is easiest to start from an array of arrays:
data grid API it is easiest to start from an array of arrays.
This demo starts by fetching a remote file and using `XLSX.read` to extract:
```js
import { useEffect, useState } from "react";

View File

@ -11,6 +11,16 @@ function blobify(data) {
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
if(typeof Deno !== 'undefined') {
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
if(enc) switch(enc) {
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
case "binary": payload = s2ab(payload); break;
/* TODO: binary equivalent */
default: throw new Error("Unsupported encoding " + enc);
}
return Deno.writeFileSync(fname, payload);
}
var data = (enc == "utf8") ? utf8write(payload) : payload;
/*:: declare var IE_SaveFile: any; */
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
@ -50,6 +60,7 @@ function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/* read binary data from file */
function read_binary(path/*:string*/) {
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
if(typeof Deno !== 'undefined') return Deno.readFileSync(path);
// $FlowIgnore
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
// $FlowIgnore

View File

@ -146,7 +146,7 @@ function fuzzydate(s/*:string*/)/*:Date*/ {
if(isNaN(d)) return n;
var lower = s.toLowerCase();
if(lower.match(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/)) {
lower = lower.replace(/[^a-z]/g,"");
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
} else if(lower.match(/[a-z]/)) return n;
if(y < 0 || y > 8099) return n;

View File

@ -508,7 +508,7 @@ var SYLK = (function() {
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || cell.v; break;
case 'd': o += '"' + (cell.w || cell.v) + '"'; break;
case 's': o += '"' + cell.v.replace(/"/g,"") + '"'; break;
case 's': o += '"' + cell.v.replace(/"/g,"").replace(/;/g, ";;") + '"'; break;
}
return o;
}

View File

@ -72,7 +72,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
_ssfopts = {};
if(o.dateNF) _ssfopts.dateNF = o.dateNF;
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); }
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); if(typeof Uint8Array !== 'undefined' && !has_buf) o.type = "array"; }
if(o.type == "string") { str = true; o.type = "binary"; o.codepage = 65001; d = bstrify(data); }
if(o.type == 'array' && typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && typeof ArrayBuffer !== 'undefined') {
// $FlowIgnore

View File

@ -48,6 +48,7 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type}) : z.generate(oopts);
if(typeof Deno !== "undefined" && typeof out == "string") out = new Uint8Array(s2ab(out));
/*jshint -W083 */
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef
/*jshint +W083 */

11
demos/deno/Makefile Normal file
View File

@ -0,0 +1,11 @@
TESTS= x mjs jspm
UNSTABLE= node
.PHONY: test
test: $(UNSTABLE) $(TESTS)
$(TESTS): %: %.ts doit.ts
deno run --allow-read --allow-write $<
# --unstable is required, see https://github.com/denoland/deno_std/issues/1900
$(UNSTABLE): %: %.ts doit.ts
deno run --allow-read --allow-write --unstable $<

74
demos/deno/README.md Normal file
View File

@ -0,0 +1,74 @@
# Deno
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.
## 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 */
```
_Writing a File_
Older versions of the library did not properly detect features from Deno, so the
`buffer` export would return an array of bytes. Since `Deno.writeFileSync` does
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);
```
## Demos
All demos attempt to read a file and write a new file. [`doit.ts`](./doit.ts)
accepts the `XLSX` module as an argument.
- `x` imports the ESM build without the codepage library:
```ts
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs';
```
- `mjs` imports the ESM build and the associated codepage library:
```ts
import * as XLSX from '../../xlsx.mjs';
/* recommended for reading XLS files */
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
import { createRequire } from 'https://deno.land/std/node/module.ts';
const require = createRequire(import.meta.url);
const XLSX = require('../../');
```
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

43
demos/deno/doit.ts Normal file
View File

@ -0,0 +1,43 @@
const bts = [
"xlsx",
"xlsb",
"xls",
"csv",
"fods",
"xlml",
"slk"
];
export default function doit(XLSX: any, tag: string) {
const path = "number_format_greek.xls";
let workbook: any;
/* read file */
try {
workbook = XLSX.readFile(path);
} catch(e) {
console.log(e);
console.error("Cannot use readFile, falling back to read");
const rawdata = Deno.readFileSync(path);
workbook = XLSX.read(rawdata, {type: "buffer"});
}
/* write file */
try {
bts.forEach(bt => {
console.log(bt);
XLSX.writeFile(workbook, `${tag}.${bt}`);
});
} catch(e) {
console.log(e);
console.error("Cannot use writeFile, falling back to write");
bts.forEach(bt => {
console.log(bt);
const buf = XLSX.write(workbook, {type: "buffer", bookType: bt});
if(typeof buf == "string") {
const nbuf = new Uint8Array(buf.length);
for(let i = 0; i < buf.length; ++i) nbuf[i] = buf.charCodeAt(i);
Deno.writeFileSync(`${tag}.${bt}`, nbuf);
} else Deno.writeFileSync(`${tag}.${bt}`, new Uint8Array(buf));
});
}
}

4
demos/deno/jspm.ts Normal file
View File

@ -0,0 +1,4 @@
import * as XLSX from 'https://jspm.dev/npm:xlsx!cjs'
import doit from './doit.ts';
doit(XLSX, "jspm");

6
demos/deno/mjs.ts Normal file
View File

@ -0,0 +1,6 @@
import * as XLSX from '../../xlsx.mjs';
import * as cpexcel from '../../dist/cpexcel.full.mjs';
XLSX.set_cptable(cpexcel);
import doit from './doit.ts';
doit(XLSX, "mjs");

6
demos/deno/node.ts Normal file
View File

@ -0,0 +1,6 @@
import { createRequire } from 'https://deno.land/std/node/module.ts';
const require = createRequire(import.meta.url);
const XLSX = require('../../');
import doit from './doit.ts';
doit(XLSX, "node");

4
demos/deno/x.ts Normal file
View File

@ -0,0 +1,4 @@
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs';
import doit from './doit.ts';
doit(XLSX, "x");

1502
dist/cpexcel.full.mjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,8 @@
### Installation
**Standalone Browser Scripts**
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:
@ -51,18 +53,50 @@ be configured to remove support with `resolve.alias`:
</details>
With [bower](https://bower.io/search/?q=js-xlsx):
```bash
$ bower install js-xlsx
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is available on deno:
```ts
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
```
**NodeJS**
With [npm](https://www.npmjs.org/package/xlsx):
```bash
$ npm install xlsx
```
With [bower](https://bower.io/search/?q=js-xlsx):
By default, the module supports `require`:
```bash
$ bower install js-xlsx
```js
var XLSX = require("xlsx");
```
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);
```
**PhotoShop and InDesign**
`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:

View File

@ -1,6 +1,6 @@
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -55,3 +55,21 @@ var debom = function(data/*:string*/)/*:string*/ {
var _getchar = function _gc1(x/*:number*/)/*:string*/ { return String.fromCharCode(x); };
var _getansi = function _ga1(x/*:number*/)/*:string*/ { return String.fromCharCode(x); };
var cptable;
function set_cptable(_cptable) {
cptable = _cptable;
set_cp = function(cp/*:number*/) { current_codepage = cp; set_ansi(cp); };
debom = function(data/*:string*/) {
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.slice(2))); }
return data;
};
_getchar = function _gc2(x/*:number*/)/*:string*/ {
if(current_codepage === 1200) return String.fromCharCode(x);
return cptable.utils.decode(current_codepage, [x&255,x>>8])[0];
};
_getansi = function _ga2(x/*:number*/)/*:string*/ {
return cptable.utils.decode(current_ansi, [x])[0];
};
}
export { set_cptable };

View File

@ -1,60 +0,0 @@
import * as _fs from 'fs';
/* normalize data for blob ctor */
function blobify(data) {
if(typeof data === "string") return s2ab(data);
if(Array.isArray(data)) return a2u(data);
return data;
}
/* write or download file */
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
var data = (enc == "utf8") ? utf8write(payload) : payload;
/*:: declare var IE_SaveFile: any; */
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
if(typeof Blob !== 'undefined') {
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
/*:: declare var navigator: any; */
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
/*:: declare var saveAs: any; */
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
var url = URL.createObjectURL(blob);
/*:: declare var chrome: any; */
if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") {
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
return chrome.downloads.download({ url: url, filename: fname, saveAs: true});
}
var a = document.createElement("a");
if(a.download != null) {
/*:: if(document.body == null) throw new Error("unreachable"); */
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
/*:: if(document.body == null) throw new Error("unreachable"); */ document.body.removeChild(a);
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
return url;
}
}
}
// $FlowIgnore
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
// $FlowIgnore
var out = File(fname); out.open("w"); out.encoding = "binary";
if(Array.isArray(payload)) payload = a2s(payload);
out.write(payload); out.close(); return payload;
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
throw new Error("cannot save file " + fname);
}
/* read binary data from file */
function read_binary(path/*:string*/) {
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
// $FlowIgnore
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
// $FlowIgnore
var infile = File(path); infile.open("r"); infile.encoding = "binary";
var data = infile.read(); infile.close();
return data;
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
throw new Error("Cannot access file " + path);
}

View File

@ -1,4 +1,6 @@
const _fs = void 0;
let _fs = void 0;
function set_fs(fs) { _fs = fs; }
export { set_fs };
/* normalize data for blob ctor */
function blobify(data) {
@ -10,6 +12,16 @@ function blobify(data) {
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
if(typeof Deno !== 'undefined') {
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
if(enc) switch(enc) {
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
case "binary": payload = s2ab(payload); break;
/* TODO: binary equivalent */
default: throw new Error("Unsupported encoding " + enc);
}
return Deno.writeFileSync(fname, payload);
}
var data = (enc == "utf8") ? utf8write(payload) : payload;
/*:: declare var IE_SaveFile: any; */
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
@ -49,6 +61,7 @@ function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/* read binary data from file */
function read_binary(path/*:string*/) {
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
if(typeof Deno !== 'undefined') return Deno.readFileSync(path);
// $FlowIgnore
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
// $FlowIgnore

View File

@ -113,6 +113,8 @@ port calculations to web apps; automate common spreadsheet tasks, and much more!
### Installation
**Standalone Browser Scripts**
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:
@ -156,18 +158,50 @@ be configured to remove support with `resolve.alias`:
With [bower](https://bower.io/search/?q=js-xlsx):
```bash
$ bower install js-xlsx
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is available on deno:
```ts
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
```
**NodeJS**
With [npm](https://www.npmjs.org/package/xlsx):
```bash
$ npm install xlsx
```
With [bower](https://bower.io/search/?q=js-xlsx):
By default, the module supports `require`:
```bash
$ bower install js-xlsx
```js
var XLSX = require("xlsx");
```
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);
```
**PhotoShop and InDesign**
`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:
@ -1541,7 +1575,9 @@ data grid for previewing and modifying structured data in the web browser. The
[`react-data-grid`](https://npm.im/react-data-grid) is a data grid tailored for
react. It expects two properties: `rows` of data objects and `columns` which
describe the columns. For the purposes of massaging the data to fit the react
data grid API it is easiest to start from an array of arrays:
data grid API it is easiest to start from an array of arrays.
This demo starts by fetching a remote file and using `XLSX.read` to extract:
```js
import { useEffect, useState } from "react";

View File

@ -1,79 +0,0 @@
misc/00_esmheader.js
bits/01_version.js
misc/02_codepage.js
bits/03_consts.js
bits/04_base64.js
bits/05_buf.js
bits/09_types.js
bits/10_ssf.js
bits/11_ssfutils.js
misc/18_esmcfb.js
misc/19_esmfs.js
bits/20_jsutils.js
misc/21_ziputils.js
bits/22_xmlutils.js
bits/23_binutils.js
bits/24_hoppers.js
bits/25_cellutils.js
bits/27_csfutils.js
bits/28_binstructs.js
bits/29_xlsenum.js
bits/30_ctype.js
bits/31_rels.js
bits/32_odmanrdf.js
bits/33_coreprops.js
bits/34_extprops.js
bits/35_custprops.js
bits/36_xlsprops.js
bits/38_xlstypes.js
bits/39_xlsbiff.js
bits/40_harb.js
bits/41_lotus.js
bits/42_sstxml.js
bits/43_sstbin.js
bits/44_offcrypto.js
bits/45_rtf.js
bits/46_stycommon.js
bits/47_styxml.js
bits/48_stybin.js
bits/49_theme.js
bits/50_styxls.js
bits/52_calcchain.js
bits/53_externlink.js
bits/54_drawing.js
bits/55_vml.js
bits/56_cmntcommon.js
bits/57_cmntxml.js
bits/58_cmntbin.js
bits/59_vba.js
bits/60_macrovba.js
bits/61_fcommon.js
bits/62_fxls.js
bits/63_fbin.js
bits/64_ftab.js
bits/65_fods.js
bits/66_wscommon.js
bits/67_wsxml.js
bits/68_wsbin.js
bits/69_chartxml.js
bits/70_csheet.js
bits/71_wbcommon.js
bits/72_wbxml.js
bits/73_wbbin.js
bits/74_xmlbin.js
bits/75_xlml.js
bits/76_xls.js
bits/77_parsetab.js
bits/78_writebiff.js
bits/79_html.js
bits/80_parseods.js
bits/81_writeods.js
bits/83_numbers.js
bits/84_defaults.js
bits/85_parsezip.js
bits/86_writezip.js
bits/87_read.js
bits/88_write.js
bits/90_utils.js
bits/95_api.js
misc/98_esmxport.js

15
types/index.d.ts vendored
View File

@ -1,16 +1,23 @@
/* index.d.ts (C) 2015-present SheetJS and contributors */
// TypeScript Version: 2.2
import * as CFB from "cfb";
import * as SSF from "ssf";
// import * as CFB from "cfb";
// import * as SSF from "ssf";
/** Version string */
export const version: string;
/** SSF Formatter Library */
export { SSF };
// export { SSF };
export const SSF: any;
/** CFB Library */
export { CFB };
// export { CFB };
export const CFB: any;
/** ESM ONLY! Set internal `fs` instance */
export function set_fs(fs: any): void;
/** ESM ONLY! Set internal codepage tables */
export function set_cptable(cptable: any): void;
/** NODE ONLY! Attempts to read filename and parse */
export function readFile(filename: string, opts?: ParsingOptions): WorkBook;

View File

@ -75,5 +75,5 @@ const headers: string[] = get_header_row(aoa2);
const CFB = XLSX.CFB;
const vbawb = XLSX.readFile("test.xlsm", {bookVBA:true});
if(vbawb.vbaraw) {
const cfb: XLSX.CFB.CFB$Container = CFB.read(vbawb.vbaraw, {type: "buffer"});
const cfb: any /* XLSX.CFB.CFB$Container */ = CFB.read(vbawb.vbaraw, {type: "buffer"});
}

23215
xlsx.esm.mjs generated

File diff suppressed because it is too large Load Diff

43
xlsx.mjs generated
View File

@ -6,7 +6,7 @@ var XLSX = {};
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -61,6 +61,24 @@ var debom = function(data/*:string*/)/*:string*/ {
var _getchar = function _gc1(x/*:number*/)/*:string*/ { return String.fromCharCode(x); };
var _getansi = function _ga1(x/*:number*/)/*:string*/ { return String.fromCharCode(x); };
var cptable;
function set_cptable(_cptable) {
cptable = _cptable;
set_cp = function(cp/*:number*/) { current_codepage = cp; set_ansi(cp); };
debom = function(data/*:string*/) {
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.slice(2))); }
return data;
};
_getchar = function _gc2(x/*:number*/)/*:string*/ {
if(current_codepage === 1200) return String.fromCharCode(x);
return cptable.utils.decode(current_codepage, [x&255,x>>8])[0];
};
_getansi = function _ga2(x/*:number*/)/*:string*/ {
return cptable.utils.decode(current_ansi, [x])[0];
};
}
export { set_cptable };
var DENSE = null;
var DIF_XL = true;
var Base64 = function() {
@ -2793,6 +2811,16 @@ function blobify(data) {
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
if(typeof Deno !== 'undefined') {
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
if(enc) switch(enc) {
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
case "binary": payload = s2ab(payload); break;
/* TODO: binary equivalent */
default: throw new Error("Unsupported encoding " + enc);
}
return Deno.writeFileSync(fname, payload);
}
var data = (enc == "utf8") ? utf8write(payload) : payload;
/*:: declare var IE_SaveFile: any; */
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
@ -2832,6 +2860,7 @@ function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
/* read binary data from file */
function read_binary(path/*:string*/) {
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
if(typeof Deno !== 'undefined') return Deno.readFileSync(path);
// $FlowIgnore
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
// $FlowIgnore
@ -2982,13 +3011,18 @@ function fuzzynum(s/*:string*/)/*:number*/ {
if(!isNaN(v = Number(ss))) return v / wt;
return v;
}
var lower_months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
function fuzzydate(s/*:string*/)/*:Date*/ {
var o = new Date(s), n = new Date(NaN);
var y = o.getYear(), m = o.getMonth(), d = o.getDate();
if(isNaN(d)) return n;
var lower = s.toLowerCase();
if(lower.match(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/)) {
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
} else if(lower.match(/[a-z]/)) return n;
if(y < 0 || y > 8099) return n;
if((m > 0 || d > 1) && y != 101) return o;
if(s.toLowerCase().match(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/)) return o;
if(s.match(/[^-0-9:,\/\\]/)) return n;
return o;
}
@ -7540,7 +7574,7 @@ var SYLK = (function() {
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || cell.v; break;
case 'd': o += '"' + (cell.w || cell.v) + '"'; break;
case 's': o += '"' + cell.v.replace(/"/g,"") + '"'; break;
case 's': o += '"' + cell.v.replace(/"/g,"").replace(/;/g, ";;") + '"'; break;
}
return o;
}
@ -22590,7 +22624,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
_ssfopts = {};
if(o.dateNF) _ssfopts.dateNF = o.dateNF;
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); }
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); if(typeof Uint8Array !== 'undefined' && !has_buf) o.type = "array"; }
if(o.type == "string") { str = true; o.type = "binary"; o.codepage = 65001; d = bstrify(data); }
if(o.type == 'array' && typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && typeof ArrayBuffer !== 'undefined') {
// $FlowIgnore
@ -22682,6 +22716,7 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type}) : z.generate(oopts);
if(typeof Deno !== "undefined" && typeof out == "string") out = new Uint8Array(s2ab(out));
/*jshint -W083 */
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef
/*jshint +W083 */