version bump 0.18.1: ESM

This commit is contained in:
SheetJS 2022-02-13 20:28:13 -05:00
parent fbdd43a3f4
commit 8e6c0411d9
33 changed files with 2788 additions and 459 deletions

@ -24,6 +24,8 @@ jobs:
# full test
full:
runs-on: ubuntu-latest
env:
FMTS: misc # TODO: remove this
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@main

@ -51,6 +51,8 @@ make.cmd
xlsworker.js
shim.js
test.js
test.mjs
test.ts
.jscs.json
.gitmodules
.travis.yml

@ -156,16 +156,6 @@ A slimmer build is generated at `dist/xlsx.mini.min.js`. Compared to full build:
- no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003
- node stream utils removed
Webpack and Browserify builds include optional modules by default. Webpack can
be configured to remove support with `resolve.alias`:
```js
/* uncomment the lines below to remove support */
resolve: {
alias: { "./dist/cpexcel.js": "" } // <-- omit international support
}
```
</details>
@ -175,6 +165,34 @@ With [bower](https://bower.io/search/?q=js-xlsx):
$ bower install js-xlsx
```
**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);
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is hosted by Deno:
@ -1460,6 +1478,17 @@ The `writeFile` method uses platform-specific APIs to initiate the file save. In
NodeJS, `fs.readFileSync` can create a file. In the web browser, a download is
attempted using the HTML5 `download` attribute, with fallbacks for IE.
_Generate and attempt to save an XLSX file_
```js
XLSX.writeFileXLSX(workbook, filename, opts);
```
The `writeFile` method embeds a number of different export functions. This is
great for developer experience but not amenable to dead code elimination using
the current toolset. When only XLSX exports are needed, this method avoids
referencing the other export codecs.
The second `opts` argument is optional. ["Writing Options"](#writing-options)
covers the supported properties and behaviors.

@ -1 +1 @@
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';

@ -1,6 +1,10 @@
function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -127,3 +131,134 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = /*::((*/[]/*:: :any):SST)*/; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
/*::if(!wb.Props) throw "unreachable"; */
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}

@ -36,6 +36,14 @@ function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z/*:any*/, o/*:?WriteOpts*/)/*:any*/ {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -114,6 +122,15 @@ function write_binary_type(out, opts/*:WriteOpts*/)/*:any*/ {
}
}
function writeSyncXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out/*:string*/ = (writeSyncXLSX(wb, o)/*:any*/); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
@ -174,6 +191,14 @@ function writeFileSync(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOp
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOpts*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename/*:string*/, wb/*:Workbook*/, opts/*:?WriteFileOpts*/, cb/*:?(e?:ErrnoError)=>void*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;

@ -8,5 +8,7 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;

@ -6,11 +6,17 @@ ng2 ng4 ng5 ng6 ng7 ng8 ng9 ng10 ng11 ng12 ng13:
if [ -e versions/tsconfig.app.json-$@ ]; then cp versions/tsconfig.app.json-$@ tsconfig.app.json; fi
if [ -e versions/polyfills.ts-$@ ]; then cp versions/polyfills.ts-$@ src/polyfills.ts; fi
rm -rf node_modules
npm install
if [ ! -e node_modules ]; then mkdir node_modules; fi
npm install
if [ ! -e node_modules/xlsx ]; then cd node_modules; ln -s ../../../ xlsx; cd -; fi
npm run build
.PHONY: refresh
refresh: ## refresh the `xlsx` symlink to force angular to rebuild
rm -f node_modules/xlsx
cd node_modules; ln -s ../../../ xlsx; cd -
touch node_modules/xlsx
.PHONY: all
all:
for i in 2 4 5 6 7 8 9 10 11 12 13; do make ng$$i; done

@ -1,9 +1,9 @@
# Angular 2+
The library can be imported directly from TS code with:
The ESM build can be imported directly from TS code with:
```typescript
import * as XLSX from 'xlsx';
import { read, utils, writeFileXLSX } from 'xlsx';
```
This demo uses an array of arrays (type `Array<Array<any>>`) as the core state.

@ -2,7 +2,9 @@
/* vim: set ts=2: */
import { Component } from '@angular/core';
import * as XLSX from 'xlsx';
import { WorkBook, WorkSheet, WritingOptions, read, writeFileXLSX as writeFile, utils, version, set_cptable } from 'xlsx';
//import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
//set_cptable(cpexcel);
type AOA = any[][];
@ -24,9 +26,9 @@ type AOA = any[][];
export class SheetJSComponent {
data: AOA = [ [1, 2], [3, 4] ];
wopts: XLSX.WritingOptions = { bookType: 'xlsx', type: 'array' };
wopts: WritingOptions = { bookType: 'xlsx', type: 'array' };
fileName: string = 'SheetJS.xlsx';
ver: string = XLSX.version;
ver: string = version;
onFileChange(evt: any) {
/* wire up file reader */
@ -36,27 +38,27 @@ export class SheetJSComponent {
reader.onload = (e: any) => {
/* read workbook */
const ab: ArrayBuffer = e.target.result;
const wb: XLSX.WorkBook = XLSX.read(ab);
const wb: WorkBook = read(ab);
/* grab first sheet */
const wsname: string = wb.SheetNames[0];
const ws: XLSX.WorkSheet = wb.Sheets[wsname];
const ws: WorkSheet = wb.Sheets[wsname];
/* save data */
this.data = <AOA>(XLSX.utils.sheet_to_json(ws, {header: 1}));
this.data = <AOA>(utils.sheet_to_json(ws, {header: 1}));
};
reader.readAsArrayBuffer(target.files[0]);
}
export(): void {
/* generate worksheet */
const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(this.data);
const ws: WorkSheet = utils.aoa_to_sheet(this.data);
/* generate workbook and add the worksheet */
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
const wb: WorkBook = utils.book_new();
utils.book_append_sheet(wb, ws, 'Sheet1');
/* save to file */
XLSX.writeFile(wb, this.fileName);
writeFile(wb, this.fileName);
}
}

30
dist/xlsx.core.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.core.min.map generated vendored

File diff suppressed because one or more lines are too long

220
dist/xlsx.extendscript.js generated vendored

@ -160,7 +160,7 @@ var DO_NOT_EXPORT_CODEPAGE = true;
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -355,7 +355,7 @@ function utf8decode(content) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3267,6 +3267,16 @@ function blobify(data) {
function write_dl(fname, payload, enc) {
/*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;
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
if(typeof Blob !== 'undefined') {
@ -3301,6 +3311,7 @@ document.body.removeChild(a);
/* read binary data from file */
function read_binary(path) {
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
@ -3450,13 +3461,18 @@ function fuzzynum(s) {
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) {
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;
}
@ -3531,7 +3547,7 @@ function getzipbin(zip, file, safe) {
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
return o.sort();
}
@ -3906,7 +3922,7 @@ if(has_buf) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b,s,e) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b,s,e) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3915,6 +3931,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b, idx) { return b[idx]; };
var __readUInt16LE = function(b, idx) { return (b[idx+1]*(1<<8))+b[idx]; };
@ -8041,7 +8058,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;
}
@ -17444,19 +17461,19 @@ Workbook.WBProps.date1904 = true;
break;
case 'header' /*case 'Header'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].header = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].header = +parsexmltag(Rn[0]).Margin;
break;
case 'footer' /*case 'Footer'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].footer = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].footer = +parsexmltag(Rn[0]).Margin;
break;
case 'pagemargins' /*case 'PageMargins'*/:
var pagemargins = parsexmltag(Rn[0]);
if(!cursheet['!margins']) default_margins(cursheet['!margins']={},'xlml');
if(pagemargins.Top) cursheet['!margins'].top = pagemargins.Top;
if(pagemargins.Left) cursheet['!margins'].left = pagemargins.Left;
if(pagemargins.Right) cursheet['!margins'].right = pagemargins.Right;
if(pagemargins.Bottom) cursheet['!margins'].bottom = pagemargins.Bottom;
if(!isNaN(+pagemargins.Top)) cursheet['!margins'].top = +pagemargins.Top;
if(!isNaN(+pagemargins.Left)) cursheet['!margins'].left = +pagemargins.Left;
if(!isNaN(+pagemargins.Right)) cursheet['!margins'].right = +pagemargins.Right;
if(!isNaN(+pagemargins.Bottom)) cursheet['!margins'].bottom = +pagemargins.Bottom;
break;
case 'displayrighttoleft' /*case 'DisplayRightToLeft'*/:
if(!Workbook.Views) Workbook.Views = [];
@ -22867,8 +22884,12 @@ if(einfo[0] == 0x02 && typeof decrypt_std76 !== 'undefined') return decrypt_std7
}
function write_zip(wb, opts) {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -22994,6 +23015,136 @@ f = "docProps/app.xml";
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = []; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f,o) {
var x = "";
switch((o||{}).type || "base64") {
@ -23063,12 +23214,13 @@ function readSync(data, opts) {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -23147,6 +23299,14 @@ function write_cfb_ctr(cfb, o) {
function write_zip_type(wb, opts) {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb, opts) {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z, o) {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -23158,7 +23318,13 @@ function write_zip_type(wb, opts) {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type}) : z.generate(oopts);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -23182,6 +23348,7 @@ function write_string_type(out, opts, bom) {
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -23218,6 +23385,15 @@ function write_binary_type(out, opts) {
}
}
function writeSyncXLSX(wb, opts) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out = (writeSyncXLSX(wb, o)); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb, opts) {
reset_cp();
check_wb(wb);
@ -23278,6 +23454,14 @@ function writeFileSync(wb, filename, opts) {
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb, filename, opts) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename, wb, opts, cb) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -23534,10 +23718,6 @@ var utils = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -23804,6 +23984,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

32
dist/xlsx.full.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.full.min.map generated vendored

File diff suppressed because one or more lines are too long

220
dist/xlsx.js generated vendored

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -199,7 +199,7 @@ function utf8decode(content) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3111,6 +3111,16 @@ function blobify(data) {
function write_dl(fname, payload, enc) {
/*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;
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
if(typeof Blob !== 'undefined') {
@ -3145,6 +3155,7 @@ document.body.removeChild(a);
/* read binary data from file */
function read_binary(path) {
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
@ -3294,13 +3305,18 @@ function fuzzynum(s) {
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) {
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;
}
@ -3375,7 +3391,7 @@ function getzipbin(zip, file, safe) {
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
return o.sort();
}
@ -3750,7 +3766,7 @@ if(has_buf) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b,s,e) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b,s,e) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3759,6 +3775,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b, idx) { return b[idx]; };
var __readUInt16LE = function(b, idx) { return (b[idx+1]*(1<<8))+b[idx]; };
@ -7885,7 +7902,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;
}
@ -17288,19 +17305,19 @@ Workbook.WBProps.date1904 = true;
break;
case 'header' /*case 'Header'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].header = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].header = +parsexmltag(Rn[0]).Margin;
break;
case 'footer' /*case 'Footer'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].footer = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].footer = +parsexmltag(Rn[0]).Margin;
break;
case 'pagemargins' /*case 'PageMargins'*/:
var pagemargins = parsexmltag(Rn[0]);
if(!cursheet['!margins']) default_margins(cursheet['!margins']={},'xlml');
if(pagemargins.Top) cursheet['!margins'].top = pagemargins.Top;
if(pagemargins.Left) cursheet['!margins'].left = pagemargins.Left;
if(pagemargins.Right) cursheet['!margins'].right = pagemargins.Right;
if(pagemargins.Bottom) cursheet['!margins'].bottom = pagemargins.Bottom;
if(!isNaN(+pagemargins.Top)) cursheet['!margins'].top = +pagemargins.Top;
if(!isNaN(+pagemargins.Left)) cursheet['!margins'].left = +pagemargins.Left;
if(!isNaN(+pagemargins.Right)) cursheet['!margins'].right = +pagemargins.Right;
if(!isNaN(+pagemargins.Bottom)) cursheet['!margins'].bottom = +pagemargins.Bottom;
break;
case 'displayrighttoleft' /*case 'DisplayRightToLeft'*/:
if(!Workbook.Views) Workbook.Views = [];
@ -22711,8 +22728,12 @@ if(einfo[0] == 0x02 && typeof decrypt_std76 !== 'undefined') return decrypt_std7
}
function write_zip(wb, opts) {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -22838,6 +22859,136 @@ f = "docProps/app.xml";
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = []; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f,o) {
var x = "";
switch((o||{}).type || "base64") {
@ -22907,12 +23058,13 @@ function readSync(data, opts) {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -22991,6 +23143,14 @@ function write_cfb_ctr(cfb, o) {
function write_zip_type(wb, opts) {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb, opts) {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z, o) {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -23002,7 +23162,13 @@ function write_zip_type(wb, opts) {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type}) : z.generate(oopts);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -23026,6 +23192,7 @@ function write_string_type(out, opts, bom) {
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -23062,6 +23229,15 @@ function write_binary_type(out, opts) {
}
}
function writeSyncXLSX(wb, opts) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out = (writeSyncXLSX(wb, o)); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb, opts) {
reset_cp();
check_wb(wb);
@ -23122,6 +23298,14 @@ function writeFileSync(wb, filename, opts) {
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb, filename, opts) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename, wb, opts, cb) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -23378,10 +23562,6 @@ var utils = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -23648,6 +23828,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

30
dist/xlsx.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map generated vendored

File diff suppressed because one or more lines are too long

16
dist/xlsx.mini.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.mini.min.map generated vendored

File diff suppressed because one or more lines are too long

@ -40,16 +40,6 @@ A slimmer build is generated at `dist/xlsx.mini.min.js`. Compared to full build:
- no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003
- node stream utils removed
Webpack and Browserify builds include optional modules by default. Webpack can
be configured to remove support with `resolve.alias`:
```js
/* uncomment the lines below to remove support */
resolve: {
alias: { "./dist/cpexcel.js": "" } // <-- omit international support
}
```
</details>
@ -59,6 +49,34 @@ With [bower](https://bower.io/search/?q=js-xlsx):
$ bower install js-xlsx
```
**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);
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is hosted by Deno:

@ -32,6 +32,17 @@ The `writeFile` method uses platform-specific APIs to initiate the file save. In
NodeJS, `fs.readFileSync` can create a file. In the web browser, a download is
attempted using the HTML5 `download` attribute, with fallbacks for IE.
_Generate and attempt to save an XLSX file_
```js
XLSX.writeFileXLSX(workbook, filename, opts);
```
The `writeFile` method embeds a number of different export functions. This is
great for developer experience but not amenable to dead code elimination using
the current toolset. When only XLSX exports are needed, this method avoids
referencing the other export codecs.
The second `opts` argument is optional. ["Writing Options"](#writing-options)
covers the supported properties and behaviors.

@ -16,12 +16,13 @@ declare var has_buf:boolean;
declare var new_buf:any;
declare var new_raw_buf:any;
declare var new_unsafe_buf:any;
declare var Buffer_from:any;
*/
/* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*jshint eqnull:true */
/*exported CFB */
/*global Uint8Array:false, Uint16Array:false */
/*global module, require:false, process:false, Buffer:false, Uint8Array:false, Uint16Array:false */
/*::
declare var DO_NOT_EXPORT_CFB:?boolean;
@ -71,70 +72,68 @@ function signed_crc_table()/*:any*/ {
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}
var T = signed_crc_table();
var T0 = signed_crc_table();
function slice_by_16_tables(T) {
var c = 0, v = 0, n = 0, table/*:Array<number>*/ = typeof Int32Array !== 'undefined' ? new Int32Array(4096) : new Array(4096) ;
for(n = 0; n != 256; ++n) table[n] = T[n];
for(n = 0; n != 256; ++n) {
v = T[n];
for(c = 256 + n; c < 4096; c += 256) v = table[c] = (v >>> 8) ^ T[v & 0xFF];
}
var out = [];
for(n = 1; n != 16; ++n) out[n - 1] = typeof Int32Array !== 'undefined' ? table.subarray(n * 256, n * 256 + 256) : table.slice(n * 256, n * 256 + 256);
return out;
}
var TT = slice_by_16_tables(T0);
var T1 = TT[0], T2 = TT[1], T3 = TT[2], T4 = TT[3], T5 = TT[4];
var T6 = TT[5], T7 = TT[6], T8 = TT[7], T9 = TT[8], Ta = TT[9];
var Tb = TT[10], Tc = TT[11], Td = TT[12], Te = TT[13], Tf = TT[14];
function crc32_bstr(bstr/*:string*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1, L = bstr.length - 1;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^bstr.charCodeAt(i++))&0xFF];
C = (C>>>8) ^ T[(C^bstr.charCodeAt(i++))&0xFF];
}
if(i === L) C = (C>>>8) ^ T[(C ^ bstr.charCodeAt(i))&0xFF];
return C ^ -1;
var C = seed/*:: ? 0 : 0 */ ^ -1;
for(var i = 0, L = bstr.length; i < L;) C = (C>>>8) ^ T0[(C^bstr.charCodeAt(i++))&0xFF];
return ~C;
}
function crc32_buf(buf/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
if(buf.length > 10000) return crc32_buf_8(buf, seed);
var C = seed ^ -1, L = buf.length - 3;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
}
while(i < L+3) C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
return C ^ -1;
}
function crc32_buf_8(buf/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1, L = buf.length - 7;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
}
while(i < L+7) C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
return C ^ -1;
function crc32_buf(B/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
var C = seed/*:: ? 0 : 0 */ ^ -1, L = B.length - 15, i = 0;
for(; i < L;) C =
Tf[B[i++] ^ (C & 255)] ^
Te[B[i++] ^ ((C >> 8) & 255)] ^
Td[B[i++] ^ ((C >> 16) & 255)] ^
Tc[B[i++] ^ (C >>> 24)] ^
Tb[B[i++]] ^ Ta[B[i++]] ^ T9[B[i++]] ^ T8[B[i++]] ^
T7[B[i++]] ^ T6[B[i++]] ^ T5[B[i++]] ^ T4[B[i++]] ^
T3[B[i++]] ^ T2[B[i++]] ^ T1[B[i++]] ^ T0[B[i++]];
L += 15;
while(i < L) C = (C>>>8) ^ T0[(C^B[i++])&0xFF];
return ~C;
}
function crc32_str(str/*:string*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1;
for(var i = 0, L=str.length, c, d; i < L;) {
for(var i = 0, L = str.length, c = 0, d = 0; i < L;) {
c = str.charCodeAt(i++);
if(c < 0x80) {
C = (C>>>8) ^ T[(C ^ c)&0xFF];
C = (C>>>8) ^ T0[(C^c)&0xFF];
} else if(c < 0x800) {
C = (C>>>8) ^ T[(C ^ (192|((c>>6)&31)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(c&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (192|((c>>6)&31)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64; d = str.charCodeAt(i++)&1023;
C = (C>>>8) ^ T[(C ^ (240|((c>>8)&7)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((c>>2)&63)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((d>>6)&15)|((c&3)<<4)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(d&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (240|((c>>8)&7)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((c>>2)&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((d>>6)&15)|((c&3)<<4)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(d&63)))&0xFF];
} else {
C = (C>>>8) ^ T[(C ^ (224|((c>>12)&15)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((c>>6)&63)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(c&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (224|((c>>12)&15)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((c>>6)&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];
}
}
return C ^ -1;
return ~C;
}
CRC32.table = T;
CRC32.table = T0;
CRC32.bstr = crc32_bstr;
CRC32.buf = crc32_buf;
CRC32.str = crc32_str;
@ -142,7 +141,7 @@ CRC32.str = crc32_str;
/* [MS-CFB] v20171201 */
var CFB = (function _CFB(){
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
exports.version = '1.1.4';
exports.version = '1.2.1';
/* [MS-CFB] 2.6.4 */
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
var L = l.split("/"), R = r.split("/");
@ -232,6 +231,7 @@ var fs/*:: = require('fs'); */;
function get_fs() { return fs || (fs = {}); }
function parse(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ {
if(file[0] == 0x50 && file[1] == 0x4b) return parse_zip(file, options);
if((file[0] | 0x20) == 0x6d && (file[1]|0x20) == 0x69) return parse_mad(file, options);
if(file.length < 512) throw new Error("CFB file size " + file.length + " < 512");
var mver = 3;
var ssz = 512;
@ -553,7 +553,11 @@ function read_file(filename/*:string*/, options/*:CFBReadOpts*/) {
}
function read(blob/*:RawBytes|string*/, options/*:CFBReadOpts*/) {
switch(options && options.type || "base64") {
var type = options && options.type;
if(!type) {
if(has_buf && Buffer.isBuffer(blob)) type = "buffer";
}
switch(type || "base64") {
case "file": /*:: if(typeof blob !== 'string') throw "Must pass a filename when type='file'"; */return read_file(blob, options);
case "base64": /*:: if(typeof blob !== 'string') throw "Must pass a base64-encoded binary string when type='file'"; */return parse(s2a(Base64.decode(blob)), options);
case "binary": /*:: if(typeof blob !== 'string') throw "Must pass a binary string when type='file'"; */return parse(s2a(blob), options);
@ -602,22 +606,28 @@ function rebuild_cfb(cfb/*:CFBContainer*/, f/*:?boolean*/)/*:void*/ {
if(!gc && !f) return;
var now = new Date(1987, 1, 19), j = 0;
// Track which names exist
var fullPaths = Object.create ? Object.create(null) : {};
var data/*:Array<[string, CFBEntry]>*/ = [];
for(i = 0; i < cfb.FullPaths.length; ++i) {
fullPaths[cfb.FullPaths[i]] = true;
if(cfb.FileIndex[i].type === 0) continue;
data.push([cfb.FullPaths[i], cfb.FileIndex[i]]);
}
for(i = 0; i < data.length; ++i) {
var dad = dirname(data[i][0]);
s = false;
for(j = 0; j < data.length; ++j) if(data[j][0] === dad) s = true;
if(!s) data.push([dad, ({
name: filename(dad).replace("/",""),
type: 1,
clsid: HEADER_CLSID,
ct: now, mt: now,
content: null
}/*:any*/)]);
s = fullPaths[dad];
if(!s) {
data.push([dad, ({
name: filename(dad).replace("/",""),
type: 1,
clsid: HEADER_CLSID,
ct: now, mt: now,
content: null
}/*:any*/)]);
// Add name to set
fullPaths[dad] = true;
}
}
data.sort(function(x,y) { return namecmp(x[0], y[0]); });
@ -650,10 +660,15 @@ function rebuild_cfb(cfb/*:CFBContainer*/, f/*:?boolean*/)/*:void*/ {
}
function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes|string*/ {
var _opts = options || {};
/* MAD is order-sensitive, skip rebuild and sort */
if(_opts.fileType == 'mad') return write_mad(cfb, _opts);
rebuild_cfb(cfb);
if(_opts.fileType == 'zip') return write_zip(cfb, _opts);
switch(_opts.fileType) {
case 'zip': return write_zip(cfb, _opts);
//case 'mad': return write_mad(cfb, _opts);
}
var L = (function(cfb/*:CFBContainer*/)/*:Array<number>*/{
var mini_size = 0, fat_size = 0;
for(var i = 0; i < cfb.FileIndex.length; ++i) {
@ -771,19 +786,36 @@ function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
/*:: if(!file.content) throw new Error("unreachable"); */
if(file.size >= 0x1000) {
o.l = (file.start+1) << 9;
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x1FF; ++j) o.write_shift(1, 0);
if (has_buf && Buffer.isBuffer(file.content)) {
file.content.copy(o, o.l, 0, file.size);
// o is a 0-filled Buffer so just set next offset
o.l += (file.size + 511) & -512;
} else {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x1FF; ++j) o.write_shift(1, 0);
}
}
}
for(i = 1; i < cfb.FileIndex.length; ++i) {
file = cfb.FileIndex[i];
/*:: if(!file.content) throw new Error("unreachable"); */
if(file.size > 0 && file.size < 0x1000) {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x3F; ++j) o.write_shift(1, 0);
if (has_buf && Buffer.isBuffer(file.content)) {
file.content.copy(o, o.l, 0, file.size);
// o is a 0-filled Buffer so just set next offset
o.l += (file.size + 63) & -64;
} else {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x3F; ++j) o.write_shift(1, 0);
}
}
}
while(o.l < o.length) o.write_shift(1, 0);
if (has_buf) {
o.l = o.length;
} else {
// When using Buffer, already 0-filled
while(o.l < o.length) o.write_shift(1, 0);
}
return o;
}
/* [MS-CFB] 2.6.4 (Unicode 3.0.1 case conversion) */
@ -847,10 +879,13 @@ function a2s(o/*:RawBytes*/)/*:string*/ {
function write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes|string*/ {
var o = _write(cfb, options);
switch(options && options.type) {
switch(options && options.type || "buffer") {
case "file": get_fs(); fs.writeFileSync(options.filename, (o/*:any*/)); return o;
case "binary": return a2s(o);
case "base64": return Base64.encode(a2s(o));
case "binary": return typeof o == "string" ? o : a2s(o);
case "base64": return Base64.encode(typeof o == "string" ? o : a2s(o));
case "buffer": if(has_buf) return Buffer.isBuffer(o) ? o : Buffer_from(o);
/* falls through */
case "array": return typeof o == "string" ? s2a(o) : o;
}
return o;
}
@ -920,6 +955,38 @@ function read_bits_n(buf, bl, n) {
return v & f;
}
/* helpers for unaligned bit writes */
function write_bits_3(buf, bl, v) { var w = bl & 7, h = bl >>> 3;
if(w <= 5) buf[h] |= (v & 7) << w;
else {
buf[h] |= (v << w) & 0xFF;
buf[h+1] = (v&7) >> (8-w);
}
return bl + 3;
}
function write_bits_1(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v = (v&1) << w;
buf[h] |= v;
return bl + 1;
}
function write_bits_8(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v <<= w;
buf[h] |= v & 0xFF; v >>>= 8;
buf[h+1] = v;
return bl + 8;
}
function write_bits_16(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v <<= w;
buf[h] |= v & 0xFF; v >>>= 8;
buf[h+1] = v & 0xFF;
buf[h+2] = v >>> 8;
return bl + 16;
}
/* until ArrayBuffer#realloc is a thing, fake a realloc */
function realloc(b, sz/*:number*/) {
var L = b.length, M = 2*L > sz ? 2*L : sz + 5, i = 0;
@ -933,7 +1000,7 @@ function realloc(b, sz/*:number*/) {
} else if(use_typed_arrays) {
var a = new Uint8Array(M);
if(a.set) a.set(b);
else for(; i < b.length; ++i) a[i] = b[i];
else for(; i < L; ++i) a[i] = b[i];
return a;
}
b.length = M;
@ -945,30 +1012,7 @@ function zero_fill_array(n) {
var o = new Array(n);
for(var i = 0; i < n; ++i) o[i] = 0;
return o;
}var _deflate = (function() {
var _deflateRaw = (function() {
return function deflateRaw(data, out) {
var boff = 0;
while(boff < data.length) {
var L = Math.min(0xFFFF, data.length - boff);
var h = boff + L == data.length;
/* TODO: this is only type 0 stored */
out.write_shift(1, +h);
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
}
return out.l;
};
})();
return function(data) {
var buf = new_buf(50+Math.floor(data.length*1.1));
var off = _deflateRaw(data, buf);
return buf.slice(0, off);
};
})();
/* modified inflate function also moves original read head */
}
/* build tree (used for literals and lengths) */
function build_tree(clens, cmap, MAX/*:number*/)/*:number*/ {
@ -1008,6 +1052,7 @@ function build_tree(clens, cmap, MAX/*:number*/)/*:number*/ {
return maxlen;
}
/* Fixed Huffman */
var fix_lmap = use_typed_arrays ? new Uint16Array(512) : zero_fill_array(512);
var fix_dmap = use_typed_arrays ? new Uint16Array(32) : zero_fill_array(32);
if(!use_typed_arrays) {
@ -1027,8 +1072,125 @@ if(!use_typed_arrays) {
for(; i<=279; i++) clens.push(7);
for(; i<=287; i++) clens.push(8);
build_tree(clens, fix_lmap, 288);
})();var _deflateRaw = (function _deflateRawIIFE() {
var DST_LN_RE = use_typed_arrays ? new Uint8Array(0x8000) : [];
var j = 0, k = 0;
for(; j < DST_LN.length - 1; ++j) {
for(; k < DST_LN[j+1]; ++k) DST_LN_RE[k] = j;
}
for(;k < 32768; ++k) DST_LN_RE[k] = 29;
var LEN_LN_RE = use_typed_arrays ? new Uint8Array(0x103) : [];
for(j = 0, k = 0; j < LEN_LN.length - 1; ++j) {
for(; k < LEN_LN[j+1]; ++k) LEN_LN_RE[k] = j;
}
function write_stored(data, out) {
var boff = 0;
while(boff < data.length) {
var L = Math.min(0xFFFF, data.length - boff);
var h = boff + L == data.length;
out.write_shift(1, +h);
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
}
return out.l;
}
/* Fixed Huffman */
function write_huff_fixed(data, out) {
var bl = 0;
var boff = 0;
var addrs = use_typed_arrays ? new Uint16Array(0x8000) : [];
while(boff < data.length) {
var L = /* data.length - boff; */ Math.min(0xFFFF, data.length - boff);
/* write a stored block for short data */
if(L < 10) {
bl = write_bits_3(out, bl, +!!(boff + L == data.length)); // jshint ignore:line
if(bl & 7) bl += 8 - (bl & 7);
out.l = (bl / 8) | 0;
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
bl = out.l * 8;
continue;
}
bl = write_bits_3(out, bl, +!!(boff + L == data.length) + 2); // jshint ignore:line
var hash = 0;
while(L-- > 0) {
var d = data[boff];
hash = ((hash << 5) ^ d) & 0x7FFF;
var match = -1, mlen = 0;
if((match = addrs[hash])) {
match |= boff & ~0x7FFF;
if(match > boff) match -= 0x8000;
if(match < boff) while(data[match + mlen] == data[boff + mlen] && mlen < 250) ++mlen;
}
if(mlen > 2) {
/* Copy Token */
d = LEN_LN_RE[mlen];
if(d <= 22) bl = write_bits_8(out, bl, bitswap8[d+1]>>1) - 1;
else {
write_bits_8(out, bl, 3);
bl += 5;
write_bits_8(out, bl, bitswap8[d-23]>>5);
bl += 3;
}
var len_eb = (d < 8) ? 0 : ((d - 4)>>2);
if(len_eb > 0) {
write_bits_16(out, bl, mlen - LEN_LN[d]);
bl += len_eb;
}
d = DST_LN_RE[boff - match];
bl = write_bits_8(out, bl, bitswap8[d]>>3);
bl -= 3;
var dst_eb = d < 4 ? 0 : (d-2)>>1;
if(dst_eb > 0) {
write_bits_16(out, bl, boff - match - DST_LN[d]);
bl += dst_eb;
}
for(var q = 0; q < mlen; ++q) {
addrs[hash] = boff & 0x7FFF;
hash = ((hash << 5) ^ data[boff]) & 0x7FFF;
++boff;
}
L-= mlen - 1;
} else {
/* Literal Token */
if(d <= 143) d = d + 48;
else bl = write_bits_1(out, bl, 1);
bl = write_bits_8(out, bl, bitswap8[d]);
addrs[hash] = boff & 0x7FFF;
++boff;
}
}
bl = write_bits_8(out, bl, 0) - 1;
}
out.l = ((bl + 7)/8)|0;
return out.l;
}
return function _deflateRaw(data, out) {
if(data.length < 8) return write_stored(data, out);
return write_huff_fixed(data, out);
};
})();
function _deflate(data) {
var buf = new_buf(50+Math.floor(data.length*1.1));
var off = _deflateRaw(data, buf);
return buf.slice(0, off);
}
/* modified inflate function also moves original read head */
var dyn_lmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
var dyn_dmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
var dyn_cmap = use_typed_arrays ? new Uint16Array(128) : zero_fill_array(128);
@ -1132,14 +1294,12 @@ function inflate(data, usz/*:number*/) {
var sz = data[boff>>>3] | data[(boff>>>3)+1]<<8;
boff += 32;
/* push sz bytes */
if(!usz && OL < woff + sz) { outbuf = realloc(outbuf, woff + sz); OL = outbuf.length; }
if(typeof data.copy === 'function') {
// $FlowIgnore
data.copy(outbuf, woff, boff>>>3, (boff>>>3)+sz);
woff += sz; boff += 8*sz;
} else while(sz-- > 0) { outbuf[woff++] = data[boff>>>3]; boff += 8; }
if(sz > 0) {
if(!usz && OL < woff + sz) { outbuf = realloc(outbuf, woff + sz); OL = outbuf.length; }
while(sz-- > 0) { outbuf[woff++] = data[boff>>>3]; boff += 8; }
}
continue;
} else if((header >>> 1) == 1) {
} else if((header >> 1) == 1) {
/* Fixed Huffman */
max_len_1 = 9; max_len_2 = 5;
} else {
@ -1147,8 +1307,8 @@ function inflate(data, usz/*:number*/) {
boff = dyn(data, boff);
max_len_1 = dyn_len_1; max_len_2 = dyn_len_2;
}
if(!usz && (OL < woff + 32767)) { outbuf = realloc(outbuf, woff + 32767); OL = outbuf.length; }
for(;;) { // while(true) is apparently out of vogue in modern JS circles
if(!usz && (OL < woff + 32767)) { outbuf = realloc(outbuf, woff + 32767); OL = outbuf.length; }
/* ingest code and move read head */
var bits = read_bits_n(data, boff, max_len_1);
var code = (header>>>1) == 1 ? fix_lmap[bits] : dyn_lmap[bits];
@ -1179,12 +1339,13 @@ function inflate(data, usz/*:number*/) {
}
/* in the common case, manual byte copy is faster than TA set / Buffer copy */
if(!usz && OL < tgt) { outbuf = realloc(outbuf, tgt); OL = outbuf.length; }
if(!usz && OL < tgt) { outbuf = realloc(outbuf, tgt + 100); OL = outbuf.length; }
while(woff < tgt) { outbuf[woff] = outbuf[woff - dst]; ++woff; }
}
}
}
return [usz ? outbuf : outbuf.slice(0, woff), (boff+7)>>>3];
if(usz) return [outbuf, (boff+7)>>>3];
return [outbuf.slice(0, woff), (boff+7)>>>3];
}
function _inflate(payload, usz) {
@ -1242,7 +1403,6 @@ function parse_zip(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/
parse_local_file(blob, csz, usz, o, EF);
blob.l = L;
}
return o;
}
@ -1278,7 +1438,7 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
var data = blob.slice(blob.l, blob.l + _csz);
switch(meth) {
case 8: data = _inflateRawSync(blob, _usz); break;
case 0: break;
case 0: break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -1293,8 +1453,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if(_csz != csz) warn_or_throw(wrn, "Bad compressed size: " + csz + " != " + _csz);
if(_usz != usz) warn_or_throw(wrn, "Bad uncompressed size: " + usz + " != " + _usz);
var _crc32 = CRC32.buf(data, 0);
if((crc32>>0) != (_crc32>>0)) warn_or_throw(wrn, "Bad CRC32 checksum: " + crc32 + " != " + _crc32);
//var _crc32 = CRC32.buf(data, 0);
//if((crc32>>0) != (_crc32>>0)) warn_or_throw(wrn, "Bad CRC32 checksum: " + crc32 + " != " + _crc32);
cfb_add(o, name, data, {unsafe: true, mt: date});
}
function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
@ -1345,7 +1505,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
start_cd += namebuf.length;
out.push(namebuf);
/* TODO: extra fields? */
/* TODO: encryption header ? */
start_cd += outbuf.length;
out.push(outbuf);
@ -1399,6 +1562,212 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
return bconcat(([bconcat((out/*:any*/)), bconcat(cdirs), o]/*:any*/));
}
var ContentTypeMap = ({
"htm": "text/html",
"xml": "text/xml",
"gif": "image/gif",
"jpg": "image/jpeg",
"png": "image/png",
"mso": "application/x-mso",
"thmx": "application/vnd.ms-officetheme",
"sh33tj5": "application/octet-stream"
}/*:any*/);
function get_content_type(fi/*:CFBEntry*/, fp/*:string*/)/*:string*/ {
if(fi.ctype) return fi.ctype;
var ext = fi.name || "", m = ext.match(/\.([^\.]+)$/);
if(m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
if(fp) {
m = (ext = fp).match(/[\.\\]([^\.\\])+$/);
if(m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
}
return "application/octet-stream";
}
/* 76 character chunks TODO: intertwine encoding */
function write_base64_76(bstr/*:string*/)/*:string*/ {
var data = Base64.encode(bstr);
var o = [];
for(var i = 0; i < data.length; i+= 76) o.push(data.slice(i, i+76));
return o.join("\r\n") + "\r\n";
}
/*
Rules for QP:
- escape =## applies for all non-display characters and literal "="
- space or tab at end of line must be encoded
- \r\n newlines can be preserved, but bare \r and \n must be escaped
- lines must not exceed 76 characters, use soft breaks =\r\n
TODO: Some files from word appear to write line extensions with bare equals:
```
<table class=3DMsoTableGrid border=3D1 cellspacing=3D0 cellpadding=3D0 width=
="70%"
```
*/
function write_quoted_printable(text/*:string*/)/*:string*/ {
var encoded = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF=]/g, function(c) {
var w = c.charCodeAt(0).toString(16).toUpperCase();
return "=" + (w.length == 1 ? "0" + w : w);
});
encoded = encoded.replace(/ $/mg, "=20").replace(/\t$/mg, "=09");
if(encoded.charAt(0) == "\n") encoded = "=0D" + encoded.slice(1);
encoded = encoded.replace(/\r(?!\n)/mg, "=0D").replace(/\n\n/mg, "\n=0A").replace(/([^\r\n])\n/mg, "$1=0A");
var o/*:Array<string>*/ = [], split = encoded.split("\r\n");
for(var si = 0; si < split.length; ++si) {
var str = split[si];
if(str.length == 0) { o.push(""); continue; }
for(var i = 0; i < str.length;) {
var end = 76;
var tmp = str.slice(i, i + end);
if(tmp.charAt(end - 1) == "=") end --;
else if(tmp.charAt(end - 2) == "=") end -= 2;
else if(tmp.charAt(end - 3) == "=") end -= 3;
tmp = str.slice(i, i + end);
i += end;
if(i < str.length) tmp += "=";
o.push(tmp);
}
}
return o.join("\r\n");
}
function parse_quoted_printable(data/*:Array<string>*/)/*:RawBytes*/ {
var o = [];
/* unify long lines */
for(var di = 0; di < data.length; ++di) {
var line = data[di];
while(di <= data.length && line.charAt(line.length - 1) == "=") line = line.slice(0, line.length - 1) + data[++di];
o.push(line);
}
/* decode */
for(var oi = 0; oi < o.length; ++oi) o[oi] = o[oi].replace(/[=][0-9A-Fa-f]{2}/g, function($$) { return String.fromCharCode(parseInt($$.slice(1), 16)); });
return s2a(o.join("\r\n"));
}
function parse_mime(cfb/*:CFBContainer*/, data/*:Array<string>*/, root/*:string*/)/*:void*/ {
var fname = "", cte = "", ctype = "", fdata;
var di = 0;
for(;di < 10; ++di) {
var line = data[di];
if(!line || line.match(/^\s*$/)) break;
var m = line.match(/^(.*?):\s*([^\s].*)$/);
if(m) switch(m[1].toLowerCase()) {
case "content-location": fname = m[2].trim(); break;
case "content-type": ctype = m[2].trim(); break;
case "content-transfer-encoding": cte = m[2].trim(); break;
}
}
++di;
switch(cte.toLowerCase()) {
case 'base64': fdata = s2a(Base64.decode(data.slice(di).join(""))); break;
case 'quoted-printable': fdata = parse_quoted_printable(data.slice(di)); break;
default: throw new Error("Unsupported Content-Transfer-Encoding " + cte);
}
var file = cfb_add(cfb, fname.slice(root.length), fdata, {unsafe: true});
if(ctype) file.ctype = ctype;
}
function parse_mad(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ {
if(a2s(file.slice(0,13)).toLowerCase() != "mime-version:") throw new Error("Unsupported MAD header");
var root = (options && options.root || "");
// $FlowIgnore
var data = (has_buf && Buffer.isBuffer(file) ? file.toString("binary") : a2s(file)).split("\r\n");
var di = 0, row = "";
/* if root is not specified, scan for the common prefix */
for(di = 0; di < data.length; ++di) {
row = data[di];
if(!/^Content-Location:/i.test(row)) continue;
row = row.slice(row.indexOf("file"));
if(!root) root = row.slice(0, row.lastIndexOf("/") + 1);
if(row.slice(0, root.length) == root) continue;
while(root.length > 0) {
root = root.slice(0, root.length - 1);
root = root.slice(0, root.lastIndexOf("/") + 1);
if(row.slice(0,root.length) == root) break;
}
}
var mboundary = (data[1] || "").match(/boundary="(.*?)"/);
if(!mboundary) throw new Error("MAD cannot find boundary");
var boundary = "--" + (mboundary[1] || "");
var FileIndex/*:CFBFileIndex*/ = [], FullPaths/*:Array<string>*/ = [];
var o = {
FileIndex: FileIndex,
FullPaths: FullPaths
};
init_cfb(o);
var start_di, fcnt = 0;
for(di = 0; di < data.length; ++di) {
var line = data[di];
if(line !== boundary && line !== boundary + "--") continue;
if(fcnt++) parse_mime(o, data.slice(start_di, di), root);
start_di = di;
}
return o;
}
function write_mad(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:string*/ {
var opts = options || {};
var boundary = opts.boundary || "SheetJS";
boundary = '------=' + boundary;
var out = [
'MIME-Version: 1.0',
'Content-Type: multipart/related; boundary="' + boundary.slice(2) + '"',
'',
'',
''
];
var root = cfb.FullPaths[0], fp = root, fi = cfb.FileIndex[0];
for(var i = 1; i < cfb.FullPaths.length; ++i) {
fp = cfb.FullPaths[i].slice(root.length);
fi = cfb.FileIndex[i];
if(!fi.size || !fi.content || fp == "\u0001Sh33tJ5") continue;
/* Normalize filename */
fp = fp.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF]/g, function(c) {
return "_x" + c.charCodeAt(0).toString(16) + "_";
}).replace(/[\u0080-\uFFFF]/g, function(u) {
return "_u" + u.charCodeAt(0).toString(16) + "_";
});
/* Extract content as binary string */
var ca = fi.content;
// $FlowIgnore
var cstr = has_buf && Buffer.isBuffer(ca) ? ca.toString("binary") : a2s(ca);
/* 4/5 of first 1024 chars ascii -> quoted printable, else base64 */
var dispcnt = 0, L = Math.min(1024, cstr.length), cc = 0;
for(var csl = 0; csl <= L; ++csl) if((cc=cstr.charCodeAt(csl)) >= 0x20 && cc < 0x80) ++dispcnt;
var qp = dispcnt >= L * 4 / 5;
out.push(boundary);
out.push('Content-Location: ' + (opts.root || 'file:///C:/SheetJS/') + fp);
out.push('Content-Transfer-Encoding: ' + (qp ? 'quoted-printable' : 'base64'));
out.push('Content-Type: ' + get_content_type(fi, fp));
out.push('');
out.push(qp ? write_quoted_printable(cstr) : write_base64_76(cstr));
}
out.push(boundary + '--\r\n');
return out.join("\r\n");
}
function cfb_new(opts/*:?any*/)/*:CFBContainer*/ {
var o/*:CFBContainer*/ = ({}/*:any*/);
init_cfb(o, opts);

@ -9,6 +9,8 @@ export {
writeFileSync as writeFile,
writeFileSync,
writeFileAsync,
writeSyncXLSX as writeXLSX,
writeFileSyncXLSX as writeFileXLSX,
utils,
SSF,
CFB

@ -146,16 +146,6 @@ A slimmer build is generated at `dist/xlsx.mini.min.js`. Compared to full build:
- no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003
- node stream utils removed
Webpack and Browserify builds include optional modules by default. Webpack can
be configured to remove support with `resolve.alias`:
```js
/* uncomment the lines below to remove support */
resolve: {
alias: { "./dist/cpexcel.js": "" } // <-- omit international support
}
```
With [bower](https://bower.io/search/?q=js-xlsx):
@ -164,6 +154,34 @@ With [bower](https://bower.io/search/?q=js-xlsx):
$ bower install js-xlsx
```
**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);
```
**Deno**
The [`sheetjs`](https://deno.land/x/sheetjs) package is hosted by Deno:
@ -1374,6 +1392,17 @@ The `writeFile` method uses platform-specific APIs to initiate the file save. In
NodeJS, `fs.readFileSync` can create a file. In the web browser, a download is
attempted using the HTML5 `download` attribute, with fallbacks for IE.
_Generate and attempt to save an XLSX file_
```js
XLSX.writeFileXLSX(workbook, filename, opts);
```
The `writeFile` method embeds a number of different export functions. This is
great for developer experience but not amenable to dead code elimination using
the current toolset. When only XLSX exports are needed, this method avoids
referencing the other export codecs.
The second `opts` argument is optional. ["Writing Options"](#writing-options)
covers the supported properties and behaviors.

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.18.0",
"version": "0.18.1",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [
@ -21,6 +21,7 @@
"xlsx": "./bin/xlsx.njs"
},
"main": "xlsx.js",
"module": "xlsx.mjs",
"unpkg": "dist/xlsx.full.min.js",
"jsdelivr": "dist/xlsx.full.min.js",
"types": "types/index.d.ts",

22
tests/core.js generated

@ -248,7 +248,7 @@ function parsetest(x/*:string*/, wb/*:Workbook*/, full/*:boolean*/, ext/*:?strin
describe(x + ext + ' should generate CSV', function() {
wb.SheetNames.forEach(function(ws, i) {
it('#' + i + ' (' + ws + ')', function() {
X.utils.make_csv(wb.Sheets[ws]);
X.utils.sheet_to_csv(wb.Sheets[ws]);
});
});
});
@ -262,7 +262,7 @@ function parsetest(x/*:string*/, wb/*:Workbook*/, full/*:boolean*/, ext/*:?strin
describe(x + ext + ' should generate formulae', function() {
wb.SheetNames.forEach(function(ws, i) {
it('#' + i + ' (' + ws + ')', function() {
X.utils.get_formulae(wb.Sheets[ws]);
X.utils.sheet_to_formulae(wb.Sheets[ws]);
});
});
});
@ -289,7 +289,7 @@ function parsetest(x/*:string*/, wb/*:Workbook*/, full/*:boolean*/, ext/*:?strin
var name = getfile(dir, x, i, ".csv");
if(fs.existsSync(name)) it('#' + i + ' (' + ws + ')', function() {
var file = fs.readFileSync(name, 'utf-8');
var csv = X.utils.make_csv(wb.Sheets[ws]);
var csv = X.utils.sheet_to_csv(wb.Sheets[ws]);
assert.equal(fixcsv(csv), fixcsv(file), "CSV badness");
});
});
@ -299,14 +299,14 @@ function parsetest(x/*:string*/, wb/*:Workbook*/, full/*:boolean*/, ext/*:?strin
var rawjson = getfile(dir, x, i, ".rawjson");
if(fs.existsSync(rawjson)) it('#' + i + ' (' + ws + ')', function() {
var file = fs.readFileSync(rawjson, 'utf-8');
var json = X.utils.make_json(wb.Sheets[ws],{raw:true});
var json = X.utils.sheet_to_json(wb.Sheets[ws],{raw:true});
assert.equal(JSON.stringify(json), fixjson(file), "JSON badness");
});
var jsonf = getfile(dir, x, i, ".json");
if(fs.existsSync(jsonf)) it('#' + i + ' (' + ws + ')', function() {
var file = fs.readFileSync(jsonf, 'utf-8');
var json = X.utils.make_json(wb.Sheets[ws], {raw:false});
var json = X.utils.sheet_to_json(wb.Sheets[ws], {raw:false});
assert.equal(JSON.stringify(json), fixjson(file), "JSON badness");
});
});
@ -1760,7 +1760,7 @@ describe('json output', function() {
if(typeof before != 'undefined') before(bef);
else it('before', bef);
it('should use first-row headers and full sheet by default', function() {
var json = X.utils.sheet_to_json(ws, {raw: null});
var json = X.utils.sheet_to_json(ws, {raw: false});
assert.equal(json.length, data.length - 1);
assert.equal(json[0][1], "TRUE");
assert.equal(json[1][2], "bar");
@ -1769,7 +1769,7 @@ describe('json output', function() {
assert.throws(function() { seeker(json, [1,2,3], "baz"); });
});
it('should create array of arrays if header == 1', function() {
var json = X.utils.sheet_to_json(ws, {header:1, raw:""});
var json = X.utils.sheet_to_json(ws, {header:1, raw:false});
assert.equal(json.length, data.length);
assert.equal(json[1][0], "TRUE");
assert.equal(json[2][1], "bar");
@ -2322,9 +2322,9 @@ describe('corner cases', function() {
get_cell(ws,"A1").f = ""; get_cell(ws,"A1").w = "";
delete get_cell(ws,"C3").w; delete get_cell(ws,"C3").z; get_cell(ws,"C3").XF = {ifmt:14};
get_cell(ws,"A4").t = "e";
X.utils.get_formulae(ws);
X.utils.make_csv(ws);
X.utils.make_json(ws);
X.utils.sheet_to_formulae(ws);
X.utils.sheet_to_csv(ws);
X.utils.sheet_to_json(ws);
ws['!cols'] = [ {wch:6}, {wch:7}, {wch:10}, {wch:20} ];
var wb = {SheetNames:['sheetjs'], Sheets:{sheetjs:ws}};
@ -2336,7 +2336,7 @@ describe('corner cases', function() {
X.write(wb, {type: "binary", bookType: 'biff5'});
X.write(wb, {type: "binary", bookType: 'biff8'});
get_cell(ws,"A2").t = "f";
assert.throws(function() { X.utils.make_json(ws); });
assert.throws(function() { X.utils.sheet_to_json(ws); });
});
it('SSF', function() {
X.SSF.format("General", "dafuq");

4
types/index.d.ts vendored

@ -25,11 +25,15 @@ export function readFile(filename: string, opts?: ParsingOptions): WorkBook;
export function read(data: any, opts?: ParsingOptions): WorkBook;
/** Attempts to write or download workbook data to file */
export function writeFile(data: WorkBook, filename: string, opts?: WritingOptions): any;
/** Attempts to write or download workbook data to XLSX file */
export function writeFileXLSX(data: WorkBook, filename: string, opts?: WritingOptions): any;
/** Attempts to write or download workbook data to file asynchronously */
type CBFunc = () => void;
export function writeFileAsync(filename: string, data: WorkBook, opts: WritingOptions | CBFunc, cb?: CBFunc): any;
/** Attempts to write the workbook data */
export function write(data: WorkBook, opts: WritingOptions): any;
/** Attempts to write the workbook data as XLSX */
export function writeXLSX(data: WorkBook, opts: WritingOptions): any;
/** Utility Functions */
export const utils: XLSX$Utils;

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -201,7 +201,7 @@ function utf8decode(content/*:string*/) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3186,6 +3186,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);
@ -3225,6 +3235,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
@ -3375,13 +3386,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;
}
@ -3456,7 +3472,7 @@ function getzipbin(zip, file/*:string*/, safe/*:?boolean*/)/*:any*/ {
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
return o.sort();
}
@ -3831,7 +3847,7 @@ if(has_buf/*:: && typeof Buffer !== 'undefined'*/) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3840,6 +3856,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return b[idx]; };
var __readUInt16LE = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return (b[idx+1]*(1<<8))+b[idx]; };
@ -7983,7 +8000,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;
}
@ -17397,19 +17414,19 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ {
break;
case 'header' /*case 'Header'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].header = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].header = +parsexmltag(Rn[0]).Margin;
break;
case 'footer' /*case 'Footer'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].footer = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].footer = +parsexmltag(Rn[0]).Margin;
break;
case 'pagemargins' /*case 'PageMargins'*/:
var pagemargins = parsexmltag(Rn[0]);
if(!cursheet['!margins']) default_margins(cursheet['!margins']={},'xlml');
if(pagemargins.Top) cursheet['!margins'].top = pagemargins.Top;
if(pagemargins.Left) cursheet['!margins'].left = pagemargins.Left;
if(pagemargins.Right) cursheet['!margins'].right = pagemargins.Right;
if(pagemargins.Bottom) cursheet['!margins'].bottom = pagemargins.Bottom;
if(!isNaN(+pagemargins.Top)) cursheet['!margins'].top = +pagemargins.Top;
if(!isNaN(+pagemargins.Left)) cursheet['!margins'].left = +pagemargins.Left;
if(!isNaN(+pagemargins.Right)) cursheet['!margins'].right = +pagemargins.Right;
if(!isNaN(+pagemargins.Bottom)) cursheet['!margins'].bottom = +pagemargins.Bottom;
break;
case 'displayrighttoleft' /*case 'DisplayRightToLeft'*/:
if(!Workbook.Views) Workbook.Views = [];
@ -22831,8 +22848,12 @@ function parse_xlsxcfb(cfb, _opts/*:?ParseOpts*/)/*:Workbook*/ {
}
function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -22959,6 +22980,137 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = /*::((*/[]/*:: :any):SST)*/; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
/*::if(!wb.Props) throw "unreachable"; */
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f/*:RawData*/,o/*:?TypeOpts*/)/*:Array<number>*/ {
var x = "";
switch((o||{}).type || "base64") {
@ -23028,12 +23180,13 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -23113,6 +23266,14 @@ function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z/*:any*/, o/*:?WriteOpts*/)/*:any*/ {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -23124,7 +23285,13 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
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);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -23148,6 +23315,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -23184,6 +23352,15 @@ function write_binary_type(out, opts/*:WriteOpts*/)/*:any*/ {
}
}
function writeSyncXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out/*:string*/ = (writeSyncXLSX(wb, o)/*:any*/); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
@ -23244,6 +23421,14 @@ function writeFileSync(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOp
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOpts*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename/*:string*/, wb/*:Workbook*/, opts/*:?WriteFileOpts*/, cb/*:?(e?:ErrnoError)=>void*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -23506,10 +23691,6 @@ var utils/*:any*/ = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -23776,6 +23957,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

220
xlsx.js generated

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -199,7 +199,7 @@ function utf8decode(content) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3111,6 +3111,16 @@ function blobify(data) {
function write_dl(fname, payload, enc) {
/*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;
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
if(typeof Blob !== 'undefined') {
@ -3145,6 +3155,7 @@ document.body.removeChild(a);
/* read binary data from file */
function read_binary(path) {
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
@ -3294,13 +3305,18 @@ function fuzzynum(s) {
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) {
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;
}
@ -3375,7 +3391,7 @@ function getzipbin(zip, file, safe) {
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
return o.sort();
}
@ -3750,7 +3766,7 @@ if(has_buf) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b,s,e) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b,s,e) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3759,6 +3775,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b, idx) { return b[idx]; };
var __readUInt16LE = function(b, idx) { return (b[idx+1]*(1<<8))+b[idx]; };
@ -7885,7 +7902,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;
}
@ -17288,19 +17305,19 @@ Workbook.WBProps.date1904 = true;
break;
case 'header' /*case 'Header'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].header = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].header = +parsexmltag(Rn[0]).Margin;
break;
case 'footer' /*case 'Footer'*/:
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
cursheet['!margins'].footer = parsexmltag(Rn[0]).Margin;
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].footer = +parsexmltag(Rn[0]).Margin;
break;
case 'pagemargins' /*case 'PageMargins'*/:
var pagemargins = parsexmltag(Rn[0]);
if(!cursheet['!margins']) default_margins(cursheet['!margins']={},'xlml');
if(pagemargins.Top) cursheet['!margins'].top = pagemargins.Top;
if(pagemargins.Left) cursheet['!margins'].left = pagemargins.Left;
if(pagemargins.Right) cursheet['!margins'].right = pagemargins.Right;
if(pagemargins.Bottom) cursheet['!margins'].bottom = pagemargins.Bottom;
if(!isNaN(+pagemargins.Top)) cursheet['!margins'].top = +pagemargins.Top;
if(!isNaN(+pagemargins.Left)) cursheet['!margins'].left = +pagemargins.Left;
if(!isNaN(+pagemargins.Right)) cursheet['!margins'].right = +pagemargins.Right;
if(!isNaN(+pagemargins.Bottom)) cursheet['!margins'].bottom = +pagemargins.Bottom;
break;
case 'displayrighttoleft' /*case 'DisplayRightToLeft'*/:
if(!Workbook.Views) Workbook.Views = [];
@ -22711,8 +22728,12 @@ if(einfo[0] == 0x02 && typeof decrypt_std76 !== 'undefined') return decrypt_std7
}
function write_zip(wb, opts) {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -22838,6 +22859,136 @@ f = "docProps/app.xml";
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = []; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f,o) {
var x = "";
switch((o||{}).type || "base64") {
@ -22907,12 +23058,13 @@ function readSync(data, opts) {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -22991,6 +23143,14 @@ function write_cfb_ctr(cfb, o) {
function write_zip_type(wb, opts) {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb, opts) {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z, o) {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -23002,7 +23162,13 @@ function write_zip_type(wb, opts) {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type}) : z.generate(oopts);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -23026,6 +23192,7 @@ function write_string_type(out, opts, bom) {
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -23062,6 +23229,15 @@ function write_binary_type(out, opts) {
}
}
function writeSyncXLSX(wb, opts) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out = (writeSyncXLSX(wb, o)); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb, opts) {
reset_cp();
check_wb(wb);
@ -23122,6 +23298,14 @@ function writeFileSync(wb, filename, opts) {
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb, filename, opts) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename, wb, opts, cb) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -23378,10 +23562,6 @@ var utils = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -23648,6 +23828,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

@ -4,10 +4,18 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') {
if(typeof global !== 'undefined') global.cptable = require('./dist/cpexcel.js');
else if(typeof window !== 'undefined') window.cptable = require('./dist/cpexcel.js');
}
}
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 = ({
@ -62,6 +70,20 @@ 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); };
if(typeof cptable !== 'undefined') {
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];
};
}
var DENSE = null;
var DIF_XL = true;
var Base64 = function() {
@ -179,7 +201,7 @@ function utf8decode(content/*:string*/) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3164,6 +3186,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);
@ -3203,6 +3235,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
@ -3353,13 +3386,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;
}
@ -3373,11 +3411,11 @@ function split_regex(str/*:string*/, re, def/*:string*/)/*:Array<string>*/ {
}
function getdatastr(data)/*:?string*/ {
if(!data) return null;
if(data.content && data.type) return cc2str(data.content, true);
if(data.data) return debom(data.data);
if(data.asNodeBuffer && has_buf) return debom(data.asNodeBuffer().toString('binary'));
if(data.asBinary) return debom(data.asBinary());
if(data._data && data._data.getContent) return debom(cc2str(Array.prototype.slice.call(data._data.getContent(),0)));
if(data.content && data.type) return debom(cc2str(data.content));
return null;
}
@ -3426,6 +3464,12 @@ function getzipstr(zip, file/*:string*/, safe/*:?boolean*/)/*:?string*/ {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file/*:string*/, safe/*:?boolean*/)/*:any*/ {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
@ -3433,23 +3477,29 @@ function zipentries(zip) {
}
function zip_add_file(zip, path, content) {
if(zip.FullPaths) CFB.utils.cfb_add(zip, path, typeof content == "string" ? (has_buf ? Buffer_from(content) : s2a(utf8write(content))) : content);
if(zip.FullPaths) {
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
/* TODO: investigate performance in Edge 13 */
//else if(typeof TextEncoder !== "undefined") res = new TextEncoder().encode(content);
else res = utf8decode(content);
return CFB.utils.cfb_add(zip, path, res);
}
CFB.utils.cfb_add(zip, path, content);
}
else zip.file(path, content);
}
function zip_new() {
return CFB.utils.cfb_new();
}
function zip_new() { return CFB.utils.cfb_new(); }
function zip_read(d, o) {
var zip;
switch(o.type) {
case "base64": zip = CFB.read(d, { type: "base64" }); break;
case "binary": zip = CFB.read(d, { type: "binary" }); break;
case "buffer": case "array": zip = CFB.read(d, { type: "buffer" }); break;
default: throw new Error("Unrecognized type " + o.type);
case "base64": return CFB.read(d, { type: "base64" });
case "binary": return CFB.read(d, { type: "binary" });
case "buffer": case "array": return CFB.read(d, { type: "buffer" });
}
return zip;
throw new Error("Unrecognized type " + o.type);
}
function resolve_path(path/*:string*/, base/*:string*/)/*:string*/ {
@ -3797,7 +3847,7 @@ if(has_buf/*:: && typeof Buffer !== 'undefined'*/) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3806,6 +3856,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return b[idx]; };
var __readUInt16LE = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return (b[idx+1]*(1<<8))+b[idx]; };
@ -5711,7 +5762,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;
}
@ -11081,8 +11132,12 @@ function parse_xlsxcfb(cfb, _opts/*:?ParseOpts*/)/*:Workbook*/ {
}
function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -11209,6 +11264,137 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = /*::((*/[]/*:: :any):SST)*/; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
/*::if(!wb.Props) throw "unreachable"; */
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f/*:RawData*/,o/*:?TypeOpts*/)/*:Array<number>*/ {
var x = "";
switch((o||{}).type || "base64") {
@ -11278,12 +11464,13 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -11363,6 +11550,14 @@ function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z/*:any*/, o/*:?WriteOpts*/)/*:any*/ {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -11374,7 +11569,13 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
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);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -11398,6 +11599,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -11434,6 +11636,15 @@ function write_binary_type(out, opts/*:WriteOpts*/)/*:any*/ {
}
}
function writeSyncXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out/*:string*/ = (writeSyncXLSX(wb, o)/*:any*/); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
@ -11494,6 +11705,14 @@ function writeFileSync(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOp
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOpts*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename/*:string*/, wb/*:Workbook*/, opts/*:?WriteFileOpts*/, cb/*:?(e?:ErrnoError)=>void*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -11756,10 +11975,6 @@ var utils/*:any*/ = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -11901,6 +12116,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

@ -4,10 +4,17 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') {
if(typeof global !== 'undefined') global.cptable = require('./dist/cpexcel.js');
else if(typeof window !== 'undefined') window.cptable = require('./dist/cpexcel.js');
}
}
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 = ({
@ -62,6 +69,20 @@ var debom = function(data) {
var _getchar = function _gc1(x) { return String.fromCharCode(x); };
var _getansi = function _ga1(x) { return String.fromCharCode(x); };
if(typeof cptable !== 'undefined') {
set_cp = function(cp) { current_codepage = cp; set_ansi(cp); };
debom = function(data) {
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) {
if(current_codepage === 1200) return String.fromCharCode(x);
return cptable.utils.decode(current_codepage, [x&255,x>>8])[0];
};
_getansi = function _ga2(x) {
return cptable.utils.decode(current_ansi, [x])[0];
};
}
var DENSE = null;
var DIF_XL = true;
var Base64 = function() {
@ -178,7 +199,7 @@ function utf8decode(content) {
o[widx++] = (128|(c&63));
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64;
var d = str.charCodeAt(++ridx)&1023;
var d = content.charCodeAt(++ridx)&1023;
o[widx++] = (240|((c>>8)&7));
o[widx++] = (128|((c>>2)&63));
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));
@ -3090,6 +3111,16 @@ function blobify(data) {
function write_dl(fname, payload, enc) {
/*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;
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
if(typeof Blob !== 'undefined') {
@ -3124,6 +3155,7 @@ document.body.removeChild(a);
/* read binary data from file */
function read_binary(path) {
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
@ -3273,13 +3305,18 @@ function fuzzynum(s) {
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) {
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;
}
@ -3293,11 +3330,11 @@ function split_regex(str, re, def) {
}
function getdatastr(data) {
if(!data) return null;
if(data.content && data.type) return cc2str(data.content, true);
if(data.data) return debom(data.data);
if(data.asNodeBuffer && has_buf) return debom(data.asNodeBuffer().toString('binary'));
if(data.asBinary) return debom(data.asBinary());
if(data._data && data._data.getContent) return debom(cc2str(Array.prototype.slice.call(data._data.getContent(),0)));
if(data.content && data.type) return debom(cc2str(data.content));
return null;
}
@ -3346,6 +3383,12 @@ function getzipstr(zip, file, safe) {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file, safe) {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i].replace(/^Root Entry[\/]/, ""));
@ -3353,23 +3396,29 @@ function zipentries(zip) {
}
function zip_add_file(zip, path, content) {
if(zip.FullPaths) CFB.utils.cfb_add(zip, path, typeof content == "string" ? (has_buf ? Buffer_from(content) : s2a(utf8write(content))) : content);
if(zip.FullPaths) {
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
/* TODO: investigate performance in Edge 13 */
//else if(typeof TextEncoder !== "undefined") res = new TextEncoder().encode(content);
else res = utf8decode(content);
return CFB.utils.cfb_add(zip, path, res);
}
CFB.utils.cfb_add(zip, path, content);
}
else zip.file(path, content);
}
function zip_new() {
return CFB.utils.cfb_new();
}
function zip_new() { return CFB.utils.cfb_new(); }
function zip_read(d, o) {
var zip;
switch(o.type) {
case "base64": zip = CFB.read(d, { type: "base64" }); break;
case "binary": zip = CFB.read(d, { type: "binary" }); break;
case "buffer": case "array": zip = CFB.read(d, { type: "buffer" }); break;
default: throw new Error("Unrecognized type " + o.type);
case "base64": return CFB.read(d, { type: "base64" });
case "binary": return CFB.read(d, { type: "binary" });
case "buffer": case "array": return CFB.read(d, { type: "buffer" });
}
return zip;
throw new Error("Unrecognized type " + o.type);
}
function resolve_path(path, base) {
@ -3717,7 +3766,7 @@ if(has_buf) {
}
/* from js-xls */
if(typeof cptable !== 'undefined') {
function cpdoit() {
__utf16le = function(b,s,e) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
__utf8 = function(b,s,e) { return cptable.utils.decode(65001, b.slice(s,e)); };
__lpstr = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@ -3726,6 +3775,7 @@ if(typeof cptable !== 'undefined') {
__lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
__8lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}
if(typeof cptable !== 'undefined') cpdoit();
var __readUInt8 = function(b, idx) { return b[idx]; };
var __readUInt16LE = function(b, idx) { return (b[idx+1]*(1<<8))+b[idx]; };
@ -5619,7 +5669,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;
}
@ -10985,8 +11035,12 @@ if(einfo[0] == 0x02 && typeof decrypt_std76 !== 'undefined') return decrypt_std7
}
function write_zip(wb, opts) {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -11112,6 +11166,136 @@ f = "docProps/app.xml";
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb, opts) {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = []; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f,o) {
var x = "";
switch((o||{}).type || "base64") {
@ -11181,12 +11365,13 @@ function readSync(data, opts) {
reset_cp();
var o = opts||{};
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
var d = data, n = [0,0,0,0], str = false;
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_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
@ -11265,6 +11450,14 @@ function write_cfb_ctr(cfb, o) {
function write_zip_type(wb, opts) {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb, opts) {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z, o) {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -11276,7 +11469,13 @@ function write_zip_type(wb, opts) {
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type}) : z.generate(oopts);
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
if(typeof Deno !== "undefined") {
if(typeof out == "string") {
if(o.type == "binary" || o.type == "base64") return out;
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 */
@ -11300,6 +11499,7 @@ function write_string_type(out, opts, bom) {
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return Buffer_from(o, 'utf8');
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
}
}
@ -11336,6 +11536,15 @@ function write_binary_type(out, opts) {
}
}
function writeSyncXLSX(wb, opts) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out = (writeSyncXLSX(wb, o)); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb, opts) {
reset_cp();
check_wb(wb);
@ -11396,6 +11605,14 @@ function writeFileSync(wb, filename, opts) {
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb, filename, opts) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename, wb, opts, cb) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -11652,10 +11869,6 @@ var utils = {
decode_cell: decode_cell,
decode_range: decode_range,
format_cell: format_cell,
get_formulae: sheet_to_formulae,
make_csv: sheet_to_csv,
make_json: sheet_to_json,
make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
@ -11797,6 +12010,8 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.writeXLSX = writeSyncXLSX;
XLSX.writeFileXLSX = writeFileSyncXLSX;
XLSX.SSF = SSF;
if(typeof CFB !== "undefined") XLSX.CFB = CFB;
}

753
xlsx.mjs generated

@ -3,7 +3,7 @@
/*exported XLSX */
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
XLSX.version = '0.18.0';
XLSX.version = '0.18.1';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
@ -1335,12 +1335,13 @@ declare var has_buf:boolean;
declare var new_buf:any;
declare var new_raw_buf:any;
declare var new_unsafe_buf:any;
declare var Buffer_from:any;
*/
/* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*jshint eqnull:true */
/*exported CFB */
/*global Uint8Array:false, Uint16Array:false */
/*global module, require:false, process:false, Buffer:false, Uint8Array:false, Uint16Array:false */
/*::
declare var DO_NOT_EXPORT_CFB:?boolean;
@ -1390,70 +1391,68 @@ function signed_crc_table()/*:any*/ {
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}
var T = signed_crc_table();
var T0 = signed_crc_table();
function slice_by_16_tables(T) {
var c = 0, v = 0, n = 0, table/*:Array<number>*/ = typeof Int32Array !== 'undefined' ? new Int32Array(4096) : new Array(4096) ;
for(n = 0; n != 256; ++n) table[n] = T[n];
for(n = 0; n != 256; ++n) {
v = T[n];
for(c = 256 + n; c < 4096; c += 256) v = table[c] = (v >>> 8) ^ T[v & 0xFF];
}
var out = [];
for(n = 1; n != 16; ++n) out[n - 1] = typeof Int32Array !== 'undefined' ? table.subarray(n * 256, n * 256 + 256) : table.slice(n * 256, n * 256 + 256);
return out;
}
var TT = slice_by_16_tables(T0);
var T1 = TT[0], T2 = TT[1], T3 = TT[2], T4 = TT[3], T5 = TT[4];
var T6 = TT[5], T7 = TT[6], T8 = TT[7], T9 = TT[8], Ta = TT[9];
var Tb = TT[10], Tc = TT[11], Td = TT[12], Te = TT[13], Tf = TT[14];
function crc32_bstr(bstr/*:string*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1, L = bstr.length - 1;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^bstr.charCodeAt(i++))&0xFF];
C = (C>>>8) ^ T[(C^bstr.charCodeAt(i++))&0xFF];
}
if(i === L) C = (C>>>8) ^ T[(C ^ bstr.charCodeAt(i))&0xFF];
return C ^ -1;
var C = seed/*:: ? 0 : 0 */ ^ -1;
for(var i = 0, L = bstr.length; i < L;) C = (C>>>8) ^ T0[(C^bstr.charCodeAt(i++))&0xFF];
return ~C;
}
function crc32_buf(buf/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
if(buf.length > 10000) return crc32_buf_8(buf, seed);
var C = seed ^ -1, L = buf.length - 3;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
}
while(i < L+3) C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
return C ^ -1;
}
function crc32_buf_8(buf/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1, L = buf.length - 7;
for(var i = 0; i < L;) {
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
}
while(i < L+7) C = (C>>>8) ^ T[(C^buf[i++])&0xFF];
return C ^ -1;
function crc32_buf(B/*:Uint8Array|Array<number>*/, seed/*:number*/)/*:number*/ {
var C = seed/*:: ? 0 : 0 */ ^ -1, L = B.length - 15, i = 0;
for(; i < L;) C =
Tf[B[i++] ^ (C & 255)] ^
Te[B[i++] ^ ((C >> 8) & 255)] ^
Td[B[i++] ^ ((C >> 16) & 255)] ^
Tc[B[i++] ^ (C >>> 24)] ^
Tb[B[i++]] ^ Ta[B[i++]] ^ T9[B[i++]] ^ T8[B[i++]] ^
T7[B[i++]] ^ T6[B[i++]] ^ T5[B[i++]] ^ T4[B[i++]] ^
T3[B[i++]] ^ T2[B[i++]] ^ T1[B[i++]] ^ T0[B[i++]];
L += 15;
while(i < L) C = (C>>>8) ^ T0[(C^B[i++])&0xFF];
return ~C;
}
function crc32_str(str/*:string*/, seed/*:number*/)/*:number*/ {
var C = seed ^ -1;
for(var i = 0, L=str.length, c, d; i < L;) {
for(var i = 0, L = str.length, c = 0, d = 0; i < L;) {
c = str.charCodeAt(i++);
if(c < 0x80) {
C = (C>>>8) ^ T[(C ^ c)&0xFF];
C = (C>>>8) ^ T0[(C^c)&0xFF];
} else if(c < 0x800) {
C = (C>>>8) ^ T[(C ^ (192|((c>>6)&31)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(c&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (192|((c>>6)&31)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];
} else if(c >= 0xD800 && c < 0xE000) {
c = (c&1023)+64; d = str.charCodeAt(i++)&1023;
C = (C>>>8) ^ T[(C ^ (240|((c>>8)&7)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((c>>2)&63)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((d>>6)&15)|((c&3)<<4)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(d&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (240|((c>>8)&7)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((c>>2)&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((d>>6)&15)|((c&3)<<4)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(d&63)))&0xFF];
} else {
C = (C>>>8) ^ T[(C ^ (224|((c>>12)&15)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|((c>>6)&63)))&0xFF];
C = (C>>>8) ^ T[(C ^ (128|(c&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (224|((c>>12)&15)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|((c>>6)&63)))&0xFF];
C = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];
}
}
return C ^ -1;
return ~C;
}
CRC32.table = T;
CRC32.table = T0;
CRC32.bstr = crc32_bstr;
CRC32.buf = crc32_buf;
CRC32.str = crc32_str;
@ -1461,7 +1460,7 @@ CRC32.str = crc32_str;
/* [MS-CFB] v20171201 */
var CFB = (function _CFB(){
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
exports.version = '1.1.4';
exports.version = '1.2.1';
/* [MS-CFB] 2.6.4 */
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
var L = l.split("/"), R = r.split("/");
@ -1551,6 +1550,7 @@ var fs/*:: = require('fs'); */;
function get_fs() { return fs || (fs = {}); }
function parse(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ {
if(file[0] == 0x50 && file[1] == 0x4b) return parse_zip(file, options);
if((file[0] | 0x20) == 0x6d && (file[1]|0x20) == 0x69) return parse_mad(file, options);
if(file.length < 512) throw new Error("CFB file size " + file.length + " < 512");
var mver = 3;
var ssz = 512;
@ -1872,7 +1872,11 @@ function read_file(filename/*:string*/, options/*:CFBReadOpts*/) {
}
function read(blob/*:RawBytes|string*/, options/*:CFBReadOpts*/) {
switch(options && options.type || "base64") {
var type = options && options.type;
if(!type) {
if(has_buf && Buffer.isBuffer(blob)) type = "buffer";
}
switch(type || "base64") {
case "file": /*:: if(typeof blob !== 'string') throw "Must pass a filename when type='file'"; */return read_file(blob, options);
case "base64": /*:: if(typeof blob !== 'string') throw "Must pass a base64-encoded binary string when type='file'"; */return parse(s2a(Base64.decode(blob)), options);
case "binary": /*:: if(typeof blob !== 'string') throw "Must pass a binary string when type='file'"; */return parse(s2a(blob), options);
@ -1921,22 +1925,28 @@ function rebuild_cfb(cfb/*:CFBContainer*/, f/*:?boolean*/)/*:void*/ {
if(!gc && !f) return;
var now = new Date(1987, 1, 19), j = 0;
// Track which names exist
var fullPaths = Object.create ? Object.create(null) : {};
var data/*:Array<[string, CFBEntry]>*/ = [];
for(i = 0; i < cfb.FullPaths.length; ++i) {
fullPaths[cfb.FullPaths[i]] = true;
if(cfb.FileIndex[i].type === 0) continue;
data.push([cfb.FullPaths[i], cfb.FileIndex[i]]);
}
for(i = 0; i < data.length; ++i) {
var dad = dirname(data[i][0]);
s = false;
for(j = 0; j < data.length; ++j) if(data[j][0] === dad) s = true;
if(!s) data.push([dad, ({
name: filename(dad).replace("/",""),
type: 1,
clsid: HEADER_CLSID,
ct: now, mt: now,
content: null
}/*:any*/)]);
s = fullPaths[dad];
if(!s) {
data.push([dad, ({
name: filename(dad).replace("/",""),
type: 1,
clsid: HEADER_CLSID,
ct: now, mt: now,
content: null
}/*:any*/)]);
// Add name to set
fullPaths[dad] = true;
}
}
data.sort(function(x,y) { return namecmp(x[0], y[0]); });
@ -1969,10 +1979,15 @@ function rebuild_cfb(cfb/*:CFBContainer*/, f/*:?boolean*/)/*:void*/ {
}
function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes|string*/ {
var _opts = options || {};
/* MAD is order-sensitive, skip rebuild and sort */
if(_opts.fileType == 'mad') return write_mad(cfb, _opts);
rebuild_cfb(cfb);
if(_opts.fileType == 'zip') return write_zip(cfb, _opts);
switch(_opts.fileType) {
case 'zip': return write_zip(cfb, _opts);
//case 'mad': return write_mad(cfb, _opts);
}
var L = (function(cfb/*:CFBContainer*/)/*:Array<number>*/{
var mini_size = 0, fat_size = 0;
for(var i = 0; i < cfb.FileIndex.length; ++i) {
@ -2090,19 +2105,36 @@ function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
/*:: if(!file.content) throw new Error("unreachable"); */
if(file.size >= 0x1000) {
o.l = (file.start+1) << 9;
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x1FF; ++j) o.write_shift(1, 0);
if (has_buf && Buffer.isBuffer(file.content)) {
file.content.copy(o, o.l, 0, file.size);
// o is a 0-filled Buffer so just set next offset
o.l += (file.size + 511) & -512;
} else {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x1FF; ++j) o.write_shift(1, 0);
}
}
}
for(i = 1; i < cfb.FileIndex.length; ++i) {
file = cfb.FileIndex[i];
/*:: if(!file.content) throw new Error("unreachable"); */
if(file.size > 0 && file.size < 0x1000) {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x3F; ++j) o.write_shift(1, 0);
if (has_buf && Buffer.isBuffer(file.content)) {
file.content.copy(o, o.l, 0, file.size);
// o is a 0-filled Buffer so just set next offset
o.l += (file.size + 63) & -64;
} else {
for(j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
for(; j & 0x3F; ++j) o.write_shift(1, 0);
}
}
}
while(o.l < o.length) o.write_shift(1, 0);
if (has_buf) {
o.l = o.length;
} else {
// When using Buffer, already 0-filled
while(o.l < o.length) o.write_shift(1, 0);
}
return o;
}
/* [MS-CFB] 2.6.4 (Unicode 3.0.1 case conversion) */
@ -2166,10 +2198,13 @@ function a2s(o/*:RawBytes*/)/*:string*/ {
function write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes|string*/ {
var o = _write(cfb, options);
switch(options && options.type) {
switch(options && options.type || "buffer") {
case "file": get_fs(); fs.writeFileSync(options.filename, (o/*:any*/)); return o;
case "binary": return a2s(o);
case "base64": return Base64.encode(a2s(o));
case "binary": return typeof o == "string" ? o : a2s(o);
case "base64": return Base64.encode(typeof o == "string" ? o : a2s(o));
case "buffer": if(has_buf) return Buffer.isBuffer(o) ? o : Buffer_from(o);
/* falls through */
case "array": return typeof o == "string" ? s2a(o) : o;
}
return o;
}
@ -2239,6 +2274,38 @@ function read_bits_n(buf, bl, n) {
return v & f;
}
/* helpers for unaligned bit writes */
function write_bits_3(buf, bl, v) { var w = bl & 7, h = bl >>> 3;
if(w <= 5) buf[h] |= (v & 7) << w;
else {
buf[h] |= (v << w) & 0xFF;
buf[h+1] = (v&7) >> (8-w);
}
return bl + 3;
}
function write_bits_1(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v = (v&1) << w;
buf[h] |= v;
return bl + 1;
}
function write_bits_8(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v <<= w;
buf[h] |= v & 0xFF; v >>>= 8;
buf[h+1] = v;
return bl + 8;
}
function write_bits_16(buf, bl, v) {
var w = bl & 7, h = bl >>> 3;
v <<= w;
buf[h] |= v & 0xFF; v >>>= 8;
buf[h+1] = v & 0xFF;
buf[h+2] = v >>> 8;
return bl + 16;
}
/* until ArrayBuffer#realloc is a thing, fake a realloc */
function realloc(b, sz/*:number*/) {
var L = b.length, M = 2*L > sz ? 2*L : sz + 5, i = 0;
@ -2252,7 +2319,7 @@ function realloc(b, sz/*:number*/) {
} else if(use_typed_arrays) {
var a = new Uint8Array(M);
if(a.set) a.set(b);
else for(; i < b.length; ++i) a[i] = b[i];
else for(; i < L; ++i) a[i] = b[i];
return a;
}
b.length = M;
@ -2264,30 +2331,7 @@ function zero_fill_array(n) {
var o = new Array(n);
for(var i = 0; i < n; ++i) o[i] = 0;
return o;
}var _deflate = (function() {
var _deflateRaw = (function() {
return function deflateRaw(data, out) {
var boff = 0;
while(boff < data.length) {
var L = Math.min(0xFFFF, data.length - boff);
var h = boff + L == data.length;
/* TODO: this is only type 0 stored */
out.write_shift(1, +h);
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
}
return out.l;
};
})();
return function(data) {
var buf = new_buf(50+Math.floor(data.length*1.1));
var off = _deflateRaw(data, buf);
return buf.slice(0, off);
};
})();
/* modified inflate function also moves original read head */
}
/* build tree (used for literals and lengths) */
function build_tree(clens, cmap, MAX/*:number*/)/*:number*/ {
@ -2327,6 +2371,7 @@ function build_tree(clens, cmap, MAX/*:number*/)/*:number*/ {
return maxlen;
}
/* Fixed Huffman */
var fix_lmap = use_typed_arrays ? new Uint16Array(512) : zero_fill_array(512);
var fix_dmap = use_typed_arrays ? new Uint16Array(32) : zero_fill_array(32);
if(!use_typed_arrays) {
@ -2346,8 +2391,125 @@ if(!use_typed_arrays) {
for(; i<=279; i++) clens.push(7);
for(; i<=287; i++) clens.push(8);
build_tree(clens, fix_lmap, 288);
})();var _deflateRaw = (function _deflateRawIIFE() {
var DST_LN_RE = use_typed_arrays ? new Uint8Array(0x8000) : [];
var j = 0, k = 0;
for(; j < DST_LN.length - 1; ++j) {
for(; k < DST_LN[j+1]; ++k) DST_LN_RE[k] = j;
}
for(;k < 32768; ++k) DST_LN_RE[k] = 29;
var LEN_LN_RE = use_typed_arrays ? new Uint8Array(0x103) : [];
for(j = 0, k = 0; j < LEN_LN.length - 1; ++j) {
for(; k < LEN_LN[j+1]; ++k) LEN_LN_RE[k] = j;
}
function write_stored(data, out) {
var boff = 0;
while(boff < data.length) {
var L = Math.min(0xFFFF, data.length - boff);
var h = boff + L == data.length;
out.write_shift(1, +h);
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
}
return out.l;
}
/* Fixed Huffman */
function write_huff_fixed(data, out) {
var bl = 0;
var boff = 0;
var addrs = use_typed_arrays ? new Uint16Array(0x8000) : [];
while(boff < data.length) {
var L = /* data.length - boff; */ Math.min(0xFFFF, data.length - boff);
/* write a stored block for short data */
if(L < 10) {
bl = write_bits_3(out, bl, +!!(boff + L == data.length)); // jshint ignore:line
if(bl & 7) bl += 8 - (bl & 7);
out.l = (bl / 8) | 0;
out.write_shift(2, L);
out.write_shift(2, (~L) & 0xFFFF);
while(L-- > 0) out[out.l++] = data[boff++];
bl = out.l * 8;
continue;
}
bl = write_bits_3(out, bl, +!!(boff + L == data.length) + 2); // jshint ignore:line
var hash = 0;
while(L-- > 0) {
var d = data[boff];
hash = ((hash << 5) ^ d) & 0x7FFF;
var match = -1, mlen = 0;
if((match = addrs[hash])) {
match |= boff & ~0x7FFF;
if(match > boff) match -= 0x8000;
if(match < boff) while(data[match + mlen] == data[boff + mlen] && mlen < 250) ++mlen;
}
if(mlen > 2) {
/* Copy Token */
d = LEN_LN_RE[mlen];
if(d <= 22) bl = write_bits_8(out, bl, bitswap8[d+1]>>1) - 1;
else {
write_bits_8(out, bl, 3);
bl += 5;
write_bits_8(out, bl, bitswap8[d-23]>>5);
bl += 3;
}
var len_eb = (d < 8) ? 0 : ((d - 4)>>2);
if(len_eb > 0) {
write_bits_16(out, bl, mlen - LEN_LN[d]);
bl += len_eb;
}
d = DST_LN_RE[boff - match];
bl = write_bits_8(out, bl, bitswap8[d]>>3);
bl -= 3;
var dst_eb = d < 4 ? 0 : (d-2)>>1;
if(dst_eb > 0) {
write_bits_16(out, bl, boff - match - DST_LN[d]);
bl += dst_eb;
}
for(var q = 0; q < mlen; ++q) {
addrs[hash] = boff & 0x7FFF;
hash = ((hash << 5) ^ data[boff]) & 0x7FFF;
++boff;
}
L-= mlen - 1;
} else {
/* Literal Token */
if(d <= 143) d = d + 48;
else bl = write_bits_1(out, bl, 1);
bl = write_bits_8(out, bl, bitswap8[d]);
addrs[hash] = boff & 0x7FFF;
++boff;
}
}
bl = write_bits_8(out, bl, 0) - 1;
}
out.l = ((bl + 7)/8)|0;
return out.l;
}
return function _deflateRaw(data, out) {
if(data.length < 8) return write_stored(data, out);
return write_huff_fixed(data, out);
};
})();
function _deflate(data) {
var buf = new_buf(50+Math.floor(data.length*1.1));
var off = _deflateRaw(data, buf);
return buf.slice(0, off);
}
/* modified inflate function also moves original read head */
var dyn_lmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
var dyn_dmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
var dyn_cmap = use_typed_arrays ? new Uint16Array(128) : zero_fill_array(128);
@ -2451,14 +2613,12 @@ function inflate(data, usz/*:number*/) {
var sz = data[boff>>>3] | data[(boff>>>3)+1]<<8;
boff += 32;
/* push sz bytes */
if(!usz && OL < woff + sz) { outbuf = realloc(outbuf, woff + sz); OL = outbuf.length; }
if(typeof data.copy === 'function') {
// $FlowIgnore
data.copy(outbuf, woff, boff>>>3, (boff>>>3)+sz);
woff += sz; boff += 8*sz;
} else while(sz-- > 0) { outbuf[woff++] = data[boff>>>3]; boff += 8; }
if(sz > 0) {
if(!usz && OL < woff + sz) { outbuf = realloc(outbuf, woff + sz); OL = outbuf.length; }
while(sz-- > 0) { outbuf[woff++] = data[boff>>>3]; boff += 8; }
}
continue;
} else if((header >>> 1) == 1) {
} else if((header >> 1) == 1) {
/* Fixed Huffman */
max_len_1 = 9; max_len_2 = 5;
} else {
@ -2466,8 +2626,8 @@ function inflate(data, usz/*:number*/) {
boff = dyn(data, boff);
max_len_1 = dyn_len_1; max_len_2 = dyn_len_2;
}
if(!usz && (OL < woff + 32767)) { outbuf = realloc(outbuf, woff + 32767); OL = outbuf.length; }
for(;;) { // while(true) is apparently out of vogue in modern JS circles
if(!usz && (OL < woff + 32767)) { outbuf = realloc(outbuf, woff + 32767); OL = outbuf.length; }
/* ingest code and move read head */
var bits = read_bits_n(data, boff, max_len_1);
var code = (header>>>1) == 1 ? fix_lmap[bits] : dyn_lmap[bits];
@ -2498,12 +2658,13 @@ function inflate(data, usz/*:number*/) {
}
/* in the common case, manual byte copy is faster than TA set / Buffer copy */
if(!usz && OL < tgt) { outbuf = realloc(outbuf, tgt); OL = outbuf.length; }
if(!usz && OL < tgt) { outbuf = realloc(outbuf, tgt + 100); OL = outbuf.length; }
while(woff < tgt) { outbuf[woff] = outbuf[woff - dst]; ++woff; }
}
}
}
return [usz ? outbuf : outbuf.slice(0, woff), (boff+7)>>>3];
if(usz) return [outbuf, (boff+7)>>>3];
return [outbuf.slice(0, woff), (boff+7)>>>3];
}
function _inflate(payload, usz) {
@ -2561,7 +2722,6 @@ function parse_zip(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/
parse_local_file(blob, csz, usz, o, EF);
blob.l = L;
}
return o;
}
@ -2597,7 +2757,7 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
var data = blob.slice(blob.l, blob.l + _csz);
switch(meth) {
case 8: data = _inflateRawSync(blob, _usz); break;
case 0: break;
case 0: break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2612,8 +2772,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if(_csz != csz) warn_or_throw(wrn, "Bad compressed size: " + csz + " != " + _csz);
if(_usz != usz) warn_or_throw(wrn, "Bad uncompressed size: " + usz + " != " + _usz);
var _crc32 = CRC32.buf(data, 0);
if((crc32>>0) != (_crc32>>0)) warn_or_throw(wrn, "Bad CRC32 checksum: " + crc32 + " != " + _crc32);
//var _crc32 = CRC32.buf(data, 0);
//if((crc32>>0) != (_crc32>>0)) warn_or_throw(wrn, "Bad CRC32 checksum: " + crc32 + " != " + _crc32);
cfb_add(o, name, data, {unsafe: true, mt: date});
}
function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
@ -2664,7 +2824,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
start_cd += namebuf.length;
out.push(namebuf);
/* TODO: extra fields? */
/* TODO: encryption header ? */
start_cd += outbuf.length;
out.push(outbuf);
@ -2718,6 +2881,212 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
return bconcat(([bconcat((out/*:any*/)), bconcat(cdirs), o]/*:any*/));
}
var ContentTypeMap = ({
"htm": "text/html",
"xml": "text/xml",
"gif": "image/gif",
"jpg": "image/jpeg",
"png": "image/png",
"mso": "application/x-mso",
"thmx": "application/vnd.ms-officetheme",
"sh33tj5": "application/octet-stream"
}/*:any*/);
function get_content_type(fi/*:CFBEntry*/, fp/*:string*/)/*:string*/ {
if(fi.ctype) return fi.ctype;
var ext = fi.name || "", m = ext.match(/\.([^\.]+)$/);
if(m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
if(fp) {
m = (ext = fp).match(/[\.\\]([^\.\\])+$/);
if(m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
}
return "application/octet-stream";
}
/* 76 character chunks TODO: intertwine encoding */
function write_base64_76(bstr/*:string*/)/*:string*/ {
var data = Base64.encode(bstr);
var o = [];
for(var i = 0; i < data.length; i+= 76) o.push(data.slice(i, i+76));
return o.join("\r\n") + "\r\n";
}
/*
Rules for QP:
- escape =## applies for all non-display characters and literal "="
- space or tab at end of line must be encoded
- \r\n newlines can be preserved, but bare \r and \n must be escaped
- lines must not exceed 76 characters, use soft breaks =\r\n
TODO: Some files from word appear to write line extensions with bare equals:
```
<table class=3DMsoTableGrid border=3D1 cellspacing=3D0 cellpadding=3D0 width=
="70%"
```
*/
function write_quoted_printable(text/*:string*/)/*:string*/ {
var encoded = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF=]/g, function(c) {
var w = c.charCodeAt(0).toString(16).toUpperCase();
return "=" + (w.length == 1 ? "0" + w : w);
});
encoded = encoded.replace(/ $/mg, "=20").replace(/\t$/mg, "=09");
if(encoded.charAt(0) == "\n") encoded = "=0D" + encoded.slice(1);
encoded = encoded.replace(/\r(?!\n)/mg, "=0D").replace(/\n\n/mg, "\n=0A").replace(/([^\r\n])\n/mg, "$1=0A");
var o/*:Array<string>*/ = [], split = encoded.split("\r\n");
for(var si = 0; si < split.length; ++si) {
var str = split[si];
if(str.length == 0) { o.push(""); continue; }
for(var i = 0; i < str.length;) {
var end = 76;
var tmp = str.slice(i, i + end);
if(tmp.charAt(end - 1) == "=") end --;
else if(tmp.charAt(end - 2) == "=") end -= 2;
else if(tmp.charAt(end - 3) == "=") end -= 3;
tmp = str.slice(i, i + end);
i += end;
if(i < str.length) tmp += "=";
o.push(tmp);
}
}
return o.join("\r\n");
}
function parse_quoted_printable(data/*:Array<string>*/)/*:RawBytes*/ {
var o = [];
/* unify long lines */
for(var di = 0; di < data.length; ++di) {
var line = data[di];
while(di <= data.length && line.charAt(line.length - 1) == "=") line = line.slice(0, line.length - 1) + data[++di];
o.push(line);
}
/* decode */
for(var oi = 0; oi < o.length; ++oi) o[oi] = o[oi].replace(/[=][0-9A-Fa-f]{2}/g, function($$) { return String.fromCharCode(parseInt($$.slice(1), 16)); });
return s2a(o.join("\r\n"));
}
function parse_mime(cfb/*:CFBContainer*/, data/*:Array<string>*/, root/*:string*/)/*:void*/ {
var fname = "", cte = "", ctype = "", fdata;
var di = 0;
for(;di < 10; ++di) {
var line = data[di];
if(!line || line.match(/^\s*$/)) break;
var m = line.match(/^(.*?):\s*([^\s].*)$/);
if(m) switch(m[1].toLowerCase()) {
case "content-location": fname = m[2].trim(); break;
case "content-type": ctype = m[2].trim(); break;
case "content-transfer-encoding": cte = m[2].trim(); break;
}
}
++di;
switch(cte.toLowerCase()) {
case 'base64': fdata = s2a(Base64.decode(data.slice(di).join(""))); break;
case 'quoted-printable': fdata = parse_quoted_printable(data.slice(di)); break;
default: throw new Error("Unsupported Content-Transfer-Encoding " + cte);
}
var file = cfb_add(cfb, fname.slice(root.length), fdata, {unsafe: true});
if(ctype) file.ctype = ctype;
}
function parse_mad(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ {
if(a2s(file.slice(0,13)).toLowerCase() != "mime-version:") throw new Error("Unsupported MAD header");
var root = (options && options.root || "");
// $FlowIgnore
var data = (has_buf && Buffer.isBuffer(file) ? file.toString("binary") : a2s(file)).split("\r\n");
var di = 0, row = "";
/* if root is not specified, scan for the common prefix */
for(di = 0; di < data.length; ++di) {
row = data[di];
if(!/^Content-Location:/i.test(row)) continue;
row = row.slice(row.indexOf("file"));
if(!root) root = row.slice(0, row.lastIndexOf("/") + 1);
if(row.slice(0, root.length) == root) continue;
while(root.length > 0) {
root = root.slice(0, root.length - 1);
root = root.slice(0, root.lastIndexOf("/") + 1);
if(row.slice(0,root.length) == root) break;
}
}
var mboundary = (data[1] || "").match(/boundary="(.*?)"/);
if(!mboundary) throw new Error("MAD cannot find boundary");
var boundary = "--" + (mboundary[1] || "");
var FileIndex/*:CFBFileIndex*/ = [], FullPaths/*:Array<string>*/ = [];
var o = {
FileIndex: FileIndex,
FullPaths: FullPaths
};
init_cfb(o);
var start_di, fcnt = 0;
for(di = 0; di < data.length; ++di) {
var line = data[di];
if(line !== boundary && line !== boundary + "--") continue;
if(fcnt++) parse_mime(o, data.slice(start_di, di), root);
start_di = di;
}
return o;
}
function write_mad(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:string*/ {
var opts = options || {};
var boundary = opts.boundary || "SheetJS";
boundary = '------=' + boundary;
var out = [
'MIME-Version: 1.0',
'Content-Type: multipart/related; boundary="' + boundary.slice(2) + '"',
'',
'',
''
];
var root = cfb.FullPaths[0], fp = root, fi = cfb.FileIndex[0];
for(var i = 1; i < cfb.FullPaths.length; ++i) {
fp = cfb.FullPaths[i].slice(root.length);
fi = cfb.FileIndex[i];
if(!fi.size || !fi.content || fp == "\u0001Sh33tJ5") continue;
/* Normalize filename */
fp = fp.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF]/g, function(c) {
return "_x" + c.charCodeAt(0).toString(16) + "_";
}).replace(/[\u0080-\uFFFF]/g, function(u) {
return "_u" + u.charCodeAt(0).toString(16) + "_";
});
/* Extract content as binary string */
var ca = fi.content;
// $FlowIgnore
var cstr = has_buf && Buffer.isBuffer(ca) ? ca.toString("binary") : a2s(ca);
/* 4/5 of first 1024 chars ascii -> quoted printable, else base64 */
var dispcnt = 0, L = Math.min(1024, cstr.length), cc = 0;
for(var csl = 0; csl <= L; ++csl) if((cc=cstr.charCodeAt(csl)) >= 0x20 && cc < 0x80) ++dispcnt;
var qp = dispcnt >= L * 4 / 5;
out.push(boundary);
out.push('Content-Location: ' + (opts.root || 'file:///C:/SheetJS/') + fp);
out.push('Content-Transfer-Encoding: ' + (qp ? 'quoted-printable' : 'base64'));
out.push('Content-Type: ' + get_content_type(fi, fp));
out.push('');
out.push(qp ? write_quoted_printable(cstr) : write_base64_76(cstr));
}
out.push(boundary + '--\r\n');
return out.join("\r\n");
}
function cfb_new(opts/*:?any*/)/*:CFBContainer*/ {
var o/*:CFBContainer*/ = ({}/*:any*/);
init_cfb(o, opts);
@ -22438,8 +22807,12 @@ function parse_xlsxcfb(cfb, _opts/*:?ParseOpts*/)/*:Workbook*/ {
}
function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(opts.bookType == "ods") return write_ods(wb, opts);
return write_zip_xlsxb(wb, opts);
}
function write_zip_xlsxb(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
@ -22566,6 +22939,137 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
delete opts.revssf; delete opts.ssf;
return zip;
}
function write_zip_xlsx(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
_shapeid = 1024;
if(wb && !wb.SSF) {
wb.SSF = SSF.get_table();
}
if(wb && wb.SSF) {
make_ssf(SSF); SSF.load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
}
opts.rels = {}; opts.wbrels = {};
opts.Strings = /*::((*/[]/*:: :any):SST)*/; opts.Strings.Count = 0; opts.Strings.Unique = 0;
if(browser_has_Map) opts.revStrings = new Map();
else { opts.revStrings = {}; opts.revStrings.foo = []; delete opts.revStrings.foo; }
var wbext = "xml";
var vbafmt = VBAFMTS.indexOf(opts.bookType) > -1;
var ct = new_ct();
fix_write_opts(opts = opts || {});
var zip = zip_new();
var f = "", rId = 0;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
if(!wb.Props) wb.Props = {};
f = "docProps/core.xml";
zip_add_file(zip, f, write_core_props(wb.Props, opts));
ct.coreprops.push(f);
add_rels(opts.rels, 2, f, RELS.CORE_PROPS);
/*::if(!wb.Props) throw "unreachable"; */
f = "docProps/app.xml";
if(wb.Props && wb.Props.SheetNames){/* empty */}
else if(!wb.Workbook || !wb.Workbook.Sheets) wb.Props.SheetNames = wb.SheetNames;
else {
var _sn = [];
for(var _i = 0; _i < wb.SheetNames.length; ++_i)
if((wb.Workbook.Sheets[_i]||{}).Hidden != 2) _sn.push(wb.SheetNames[_i]);
wb.Props.SheetNames = _sn;
}
wb.Props.Worksheets = wb.Props.SheetNames.length;
zip_add_file(zip, f, write_ext_props(wb.Props, opts));
ct.extprops.push(f);
add_rels(opts.rels, 3, f, RELS.EXT_PROPS);
if(wb.Custprops !== wb.Props && keys(wb.Custprops||{}).length > 0) {
f = "docProps/custom.xml";
zip_add_file(zip, f, write_cust_props(wb.Custprops, opts));
ct.custprops.push(f);
add_rels(opts.rels, 4, f, RELS.CUST_PROPS);
}
for(rId=1;rId <= wb.SheetNames.length; ++rId) {
var wsrels = {'!id':{}};
var ws = wb.Sheets[wb.SheetNames[rId-1]];
var _type = (ws || {})["!type"] || "sheet";
switch(_type) {
case "chart":
/* falls through */
default:
f = "xl/worksheets/sheet" + rId + "." + wbext;
zip_add_file(zip, f, write_ws_xml(rId-1, opts, wb, wsrels));
ct.sheets.push(f);
add_rels(opts.wbrels, -1, "worksheets/sheet" + rId + "." + wbext, RELS.WS[0]);
}
if(ws) {
var comments = ws['!comments'];
var need_vml = false;
if(comments && comments.length > 0) {
var cf = "xl/comments" + rId + "." + wbext;
zip_add_file(zip, cf, write_comments_xml(comments, opts));
ct.comments.push(cf);
add_rels(wsrels, -1, "../comments" + rId + "." + wbext, RELS.CMNT);
need_vml = true;
}
if(ws['!legacy']) {
if(need_vml) zip_add_file(zip, "xl/drawings/vmlDrawing" + (rId) + ".vml", write_comments_vml(rId, ws['!comments']));
}
delete ws['!comments'];
delete ws['!legacy'];
}
if(wsrels['!id'].rId1) zip_add_file(zip, get_rels_path(f), write_rels(wsrels));
}
if(opts.Strings != null && opts.Strings.length > 0) {
f = "xl/sharedStrings." + wbext;
zip_add_file(zip, f, write_sst_xml(opts.Strings, opts));
ct.strs.push(f);
add_rels(opts.wbrels, -1, "sharedStrings." + wbext, RELS.SST);
}
f = "xl/workbook." + wbext;
zip_add_file(zip, f, write_wb_xml(wb, opts));
ct.workbooks.push(f);
add_rels(opts.rels, 1, f, RELS.WB);
/* TODO: something more intelligent with themes */
f = "xl/theme/theme1.xml";
zip_add_file(zip, f, write_theme(wb.Themes, opts));
ct.themes.push(f);
add_rels(opts.wbrels, -1, "theme/theme1.xml", RELS.THEME);
/* TODO: something more intelligent with styles */
f = "xl/styles." + wbext;
zip_add_file(zip, f, write_sty_xml(wb, opts));
ct.styles.push(f);
add_rels(opts.wbrels, -1, "styles." + wbext, RELS.STY);
if(wb.vbaraw && vbafmt) {
f = "xl/vbaProject.bin";
zip_add_file(zip, f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, -1, "vbaProject.bin", RELS.VBA);
}
zip_add_file(zip, "[Content_Types].xml", write_ct(ct, opts));
zip_add_file(zip, '_rels/.rels', write_rels(opts.rels));
zip_add_file(zip, 'xl/_rels/workbook.' + wbext + '.rels', write_rels(opts.wbrels));
delete opts.revssf; delete opts.ssf;
return zip;
}
function firstbyte(f/*:RawData*/,o/*:?TypeOpts*/)/*:Array<number>*/ {
var x = "";
switch((o||{}).type || "base64") {
@ -22721,6 +23225,14 @@ function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_typeXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
var o = dup(opts||{});
var z = write_zip_xlsx(wb, o);
return write_zip_denouement(z, o);
}
function write_zip_denouement(z/*:any*/, o/*:?WriteOpts*/)/*:any*/ {
var oopts = {};
if(o.compression) oopts.compression = 'DEFLATE';
if(o.password) oopts.type = has_buf ? "nodebuffer" : "string";
@ -22799,6 +23311,15 @@ function write_binary_type(out, opts/*:WriteOpts*/)/*:any*/ {
}
}
function writeSyncXLSX(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
var o = dup(opts||{});
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out/*:string*/ = (writeSyncXLSX(wb, o)/*:any*/); o.type = "array"; return s2ab(out); }
return write_zip_typeXLSX(wb, o);
}
function writeSync(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
reset_cp();
check_wb(wb);
@ -22859,6 +23380,14 @@ function writeFileSync(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOp
return writeSync(wb, o);
}
function writeFileSyncXLSX(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOpts*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
resolve_book_type(o);
return writeSyncXLSX(wb, o);
}
function writeFileAsync(filename/*:string*/, wb/*:Workbook*/, opts/*:?WriteFileOpts*/, cb/*:?(e?:ErrnoError)=>void*/) {
var o = opts||{}; o.type = 'file';
o.file = filename;
@ -23263,6 +23792,8 @@ export {
writeFileSync as writeFile,
writeFileSync,
writeFileAsync,
writeSyncXLSX as writeXLSX,
writeFileSyncXLSX as writeFileXLSX,
utils,
SSF,
CFB