NaN and Infinity error export

- `read` handle `Int8Array` (to support Java engines)
- `sheet_to_formulae` option to suppress values
- handle unexpected `<charset/>` (fixes #3143 h/t @dearzubi)
This commit is contained in:
SheetJS 2024-07-04 15:54:34 -04:00
parent 5ef49e2b96
commit 5a36cb423d
51 changed files with 2632 additions and 538 deletions

@ -4,6 +4,13 @@ This log is intended to keep track of backwards-incompatible changes, including
but not limited to API changes and file location changes. Minor behavioral
changes may not be included if they are not expected to break existing code.
## v0.20.3
* More precise treatment of infinite and NaN values
* XLML Streaming Write
* Parse `Int8Array` objects (for compatibility with JS engines in Java)
* CSV Export only quote leading ID (h/t @lako12)
## v0.20.2
* Reworked parsing methods to avoid slow regexes (CVE-2024-22363)

@ -152,8 +152,8 @@ test.ts: test.mts
node -pe 'var data = fs.readFileSync("'$<'", "utf8"); data.split("\n").map(function(l) { return l.replace(/^describe\((.*?)function\(\)/, "Deno.test($$1async function(t)").replace(/\b(?:it|describe)\((.*?)function\(\)/g, "await t.step($$1async function(t)").replace("assert.ok", "assert.assert"); }).join("\n")' > $@
.PHONY: test-bun
test-bun: testbun.mjs ## Run Bun test suite
bun $<
test-bun: test.test.mjs ## Run Bun test suite
bun test $<
.PHONY: test-deno
test-deno: test.ts ## Run Deno test suite

@ -1 +1 @@
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';

@ -243,7 +243,7 @@ function SSF_large_exp(v/*:number*/)/*:string*/ {
}
function SSF_general_num(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#VALUE!" : "#DIV/0!";
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -979,7 +979,7 @@ function SSF_format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#VALUE!";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}

@ -42,7 +42,9 @@ type CFBFiles = {[n:string]:CFBEntry};
var CRC32 = /*#__PURE__*/(function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*::
type CRC32TableType = Array<number> | Int32Array;
*/
/*global Int32Array */
function signed_crc_table()/*:any*/ {
var c = 0, table/*:Array<number>*/ = new Array(256);
@ -80,7 +82,7 @@ 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*/ {
function crc32_bstr(bstr/*:string*/, seed/*:?number*/)/*:number*/ {
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;
@ -1446,8 +1448,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -1458,7 +1460,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; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -1493,9 +1495,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);

@ -67,6 +67,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);

@ -32,6 +32,26 @@ function parsexmltag(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*
}
return z;
}
function parsexmltagraw(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*/)/*:any*/ {
var z = ({}/*:any*/);
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x/*:string*/)/*:string*/ { return x.replace(nsregex2, "<$1"); }
var encodings = {

@ -20,7 +20,8 @@ function recordhopper(data, cb/*:RecordHopperCB*/, opts/*:?any*/) {
/* control buffer usage for fixed-length buffers */
function buf_array()/*:BufArray*/ {
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 256 : 2048;
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz/*:number*/)/*:Block*/ {
var o/*:Block*/ = (new_buf(sz)/*:any*/);
prep_blob(o, 0);
@ -49,10 +50,15 @@ function buf_array()/*:BufArray*/ {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs }/*:any*/);
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 }/*:any*/);
}
function write_record(ba/*:BufArray*/, type/*:number*/, payload, length/*:?number*/) {

@ -119,7 +119,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
var ws/*:Worksheet*/ = _ws || (dense ? ({"!data": []}) : ({}/*:any*/));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -144,23 +144,24 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data_R[C], t:"" }/*:any*/);
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
@ -185,7 +186,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr/*:any*/;
var cell_ref = encode_col(__C) + (__R + 1)/*:any*/;
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}

@ -593,7 +593,7 @@ var SYLK = /*#__PURE__*/(function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -822,7 +822,7 @@ var ETH = /*#__PURE__*/(function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -865,11 +865,7 @@ var ETH = /*#__PURE__*/(function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -879,6 +875,19 @@ var ETH = /*#__PURE__*/(function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -910,6 +919,7 @@ var PRN = /*#__PURE__*/(function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -1027,6 +1037,8 @@ var PRN = /*#__PURE__*/(function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;

@ -598,7 +598,6 @@ var WK_ = /*#__PURE__*/(function() {
else console.error("WK1 bad formula parse |" + out.join("|") + "|");
}
function parse_cell_3(blob/*::, length*/) {
var o = [{c:0,r:0}, {t:'n',v:0}, 0];
o[0].r = blob.read_shift(2); o[3] = blob[blob.l++]; o[0].c = blob[blob.l++];

@ -49,6 +49,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;

@ -220,6 +220,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':

@ -62,7 +62,7 @@ function parse_ws_xml(data/*:?string*/, opts, idx/*:number*/, rels, wb/*:WBWBPro
var merges/*:Array<Range>*/ = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -521,16 +521,17 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th
function write_ws_xml_data(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbook*//*::, rels*/)/*:string*/ {
var o/*:Array<string>*/ = [], r/*:Array<string>*/ = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols/*:Array<string>*/ = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}/*:any*/), row/*:RowInfo*/, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}

@ -847,12 +847,15 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) {
if(last_seen) write_record(ba, 0x000D /* BrtShortRk */, write_BrtShortRk(cell, o));
else write_record(ba, 0x0002 /* BrtCellRk */, write_BrtCellRk(cell, o));
} else if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else if(!isFinite(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
o.t = "e";
if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
}
} else {
if(last_seen) write_record(ba, 0x0010 /* BrtShortReal */, write_BrtShortReal(cell, o));
else write_record(ba, 0x0005 /* BrtCellReal */, write_BrtCellReal(cell, o));
@ -874,23 +877,24 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
}
function write_CELLTABLE(ba, ws/*:Worksheet*/, idx/*:number*/, opts, wb/*:Workbook*/) {
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols/*:Array<string>*/ = [];
var range = safe_decode_range(ws['!ref'] || "A1"), rr = "", cols/*:Array<string>*/ = [];
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
write_record(ba, 0x0091 /* BrtBeginSheetData */);
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, row = dense ? ws["!data"][range.s.r] : [];
var cap = range.e.r;
if(ws['!rows']) cap = Math.max(range.e.r, ws['!rows'].length - 1);
for(var R = range.s.r; R <= cap; ++R) {
rr = encode_row(R);
if(dense) row = ws["!data"][R];
/* [ACCELLTABLE] */
/* BrtRowHdr */
write_row_header(ba, ws, range, R);
if(dense && !row) continue;
var last_seen = false;
if(R <= range.e.r) for(var C = range.s.c; C <= range.e.c; ++C) {
/* *16384CELL */
if(R === range.s.r) cols[C] = encode_col(C);
ref = cols[C] + rr;
var cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) { last_seen = false; continue; }
/* write cell */
last_seen = write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904);

@ -1144,7 +1144,13 @@ function write_ws_xlml_cell(cell, ref/*:string*/, ws, opts, idx/*:number*/, wb,
var t = "", p = "";
switch(cell.t) {
case 'z': if(!opts.sheetStubs) return ""; break;
case 'n': t = 'Number'; p = String(cell.v); break;
case 'n': {
if(!isFinite(cell.v)) {
t = 'Error'; p = BErr[isNaN(cell.v) ? 0x24 : 0x07];
} else {
t = 'Number'; p = String(cell.v);
}
} break;
case 'b': t = 'Boolean'; p = (cell.v ? "1" : "0"); break;
case 'e': t = 'Error'; p = BErr[cell.v]; break;
case 'd': t = 'DateTime'; p = new Date(cell.v).toISOString(); if(cell.z == null) cell.z = cell.z || table_fmt[14]; break;

@ -48,6 +48,8 @@ function html_to_sheet(str/*:string*/, _opts)/*:Workbook*/ {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -75,6 +77,10 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({}/*:any*/);
@ -185,6 +191,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -193,7 +200,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.

@ -247,7 +247,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
var Sheets = {}, SheetNames/*:Array<string>*/ = [];
var ws = ({}/*:any*/); if(opts.dense) ws["!data"] = [];
var Rn, q/*:: :any = ({t:"", v:null, z:null, w:"",c:[],}:any)*/;
var ctag = ({value:""}/*:any*/);
var ctag = ({value:""}/*:any*/), ctag2 = ({}/*:any*/);
var textp = "", textpidx = 0, textptag/*:: = {}*/, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -341,6 +341,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({}/*:any*/);
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null/*:: , z:null, w:"",c:[]*/}/*:any*/);
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -394,6 +395,9 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;

@ -262,9 +262,22 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = /* @__PURE__ */(function
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;

@ -75,6 +75,8 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }

@ -159,7 +159,7 @@ function sheet_to_txt(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
function sheet_to_formulae(sheet/*:Worksheet*/, opts/*:?Sheet2FormulaOpts*/)/*:Array<string>*/ {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols/*:Array<string>*/ = [], C;
@ -180,6 +180,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";

@ -119,6 +119,7 @@ function write_json_stream(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
var stream = _Readable();
var opts = o == null ? {} : o;
var stride = +opts.stride || 10;
if(!wb.SSF) wb.SSF = dup(table_fmt);
if(wb.SSF) {
make_ssf(); SSF_load_table(wb.SSF);
@ -205,7 +206,7 @@ function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
/* worksheet intramble */
case 4: {
if(R < 0 || R > range.e.r) { stream.push(T ? "</Table>" : ""); return void (stage = 5); }
if(R < 0 || R > range.e.r) { if(T) stream.push("</Table>"); return void (stage = 5); }
if(R <= range.s.r) {
if(ws['!cols']) ws['!cols'].forEach(function(n, i) {
@ -223,8 +224,8 @@ function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
addr.r = addr.c = 0;
}
/* process 10 rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < 10; ++R, ++cnt) {
/* process `stride` rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < stride; ++R, ++cnt) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
if(!(dense && !darr[R])) for(var C = range.s.c; C <= range.e.c; ++C) {
@ -243,10 +244,8 @@ function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
row.push(write_ws_xlml_cell(cell, ref, ws, opts, wsidx, wb, addr));
}
row.push("</Row>");
if(row.length > 2) {
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
} break;

33
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

375
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, DataView:false, Deno:false, Set:false, Float32Array:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
var $cptable;
@ -695,6 +695,7 @@ function SSF_large_exp(v) {
}
function SSF_general_num(v) {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1388,6 +1389,8 @@ function choose_fmt(f, v) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1424,6 +1427,8 @@ function SSF_format(fmt,v,o) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt, idx) {
@ -1547,7 +1552,6 @@ function SSF__load(fmt, idx) {
var CRC32 = (function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*global Int32Array */
function signed_crc_table() {
var c = 0, table = new Array(256);
@ -2946,8 +2950,8 @@ function parse_local_file(blob, csz, usz, o, EF) {
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2958,7 +2962,7 @@ function parse_local_file(blob, csz, usz, o, EF) {
var data = blob.slice(blob.l, blob.l + _csz);
switch(meth) {
case 8: data = _inflateRawSync(blob, _usz); break;
case 0: break; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2993,9 +2997,10 @@ function write_zip(cfb, options) {
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3888,6 +3893,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3958,6 +3966,26 @@ function parsexmltag(tag, skip_root, skip_LC) {
}
return z;
}
function parsexmltagraw(tag, skip_root, skip_LC) {
var z = ({});
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x) { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4464,7 +4492,8 @@ function recordhopper(data, cb, opts) {
/* control buffer usage for fixed-length buffers */
function buf_array() {
var bufs = [], blksz = has_buf ? 256 : 2048;
var bufs = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz) {
var o = (new_buf(sz));
prep_blob(o, 0);
@ -4493,10 +4522,15 @@ function buf_array() {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs });
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 });
}
function write_record(ba, type, payload, length) {
@ -4683,7 +4717,7 @@ function sheet_add_aoa(_ws, data, opts) {
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws = _ws || ({});
var ws = _ws || (dense ? ({"!data": []}) : ({}));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4708,31 +4742,35 @@ function sheet_add_aoa(_ws, data, opts) {
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell = ({v: data[R][C] });
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell = ({v: data_R[C], t:"" });
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4746,7 +4784,7 @@ function sheet_add_aoa(_ws, data, opts) {
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr;
var cell_ref = encode_col(__C) + (__R + 1);
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4756,7 +4794,6 @@ function sheet_add_aoa(_ws, data, opts) {
return ws;
}
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
function parse_Int32LE(data) {
return data.read_shift(4, 'i');
}
@ -6338,8 +6375,8 @@ function parse_TypedPropertyValue(blob, type, _opts) {
case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
case 0x1E /*VT_LPSTR*/: return parse_lpstr(blob, t, 4).replace(chr0,'');
case 0x1F /*VT_LPWSTR*/: return parse_lpwstr(blob);
case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@ -8631,7 +8668,7 @@ var SYLK = (function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -8860,7 +8897,7 @@ var ETH = (function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -8903,11 +8940,7 @@ var ETH = (function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -8917,6 +8950,19 @@ var ETH = (function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -8948,6 +8994,7 @@ var PRN = (function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -9065,6 +9112,8 @@ var PRN = (function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -9764,7 +9813,6 @@ var WK_ = (function() {
else console.error("WK1 bad formula parse |" + out.join("|") + "|");
}
function parse_cell_3(blob) {
var o = [{c:0,r:0}, {t:'n',v:0}, 0];
o[0].r = blob.read_shift(2); o[3] = blob[blob.l++]; o[0].c = blob[blob.l++];
@ -10999,6 +11047,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;
@ -11391,6 +11443,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -15920,7 +15973,7 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
var merges = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -16379,16 +16432,17 @@ return function parse_ws_xml_data(sdata, s, opts, guess, themes, styles, wb) {
function write_ws_xml_data(ws, opts, idx, wb) {
var o = [], r = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}), row, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -17389,12 +17443,15 @@ function write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904) {
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) {
if(last_seen) write_record(ba, 0x000D /* BrtShortRk */, write_BrtShortRk(cell, o));
else write_record(ba, 0x0002 /* BrtCellRk */, write_BrtCellRk(cell, o));
} else if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else if(!isFinite(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
o.t = "e";
if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
}
} else {
if(last_seen) write_record(ba, 0x0010 /* BrtShortReal */, write_BrtShortReal(cell, o));
else write_record(ba, 0x0005 /* BrtCellReal */, write_BrtCellReal(cell, o));
@ -17416,23 +17473,24 @@ function write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904) {
}
function write_CELLTABLE(ba, ws, idx, opts, wb) {
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols = [];
var range = safe_decode_range(ws['!ref'] || "A1"), rr = "", cols = [];
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
write_record(ba, 0x0091 /* BrtBeginSheetData */);
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, row = dense ? ws["!data"][range.s.r] : [];
var cap = range.e.r;
if(ws['!rows']) cap = Math.max(range.e.r, ws['!rows'].length - 1);
for(var R = range.s.r; R <= cap; ++R) {
rr = encode_row(R);
if(dense) row = ws["!data"][R];
/* [ACCELLTABLE] */
/* BrtRowHdr */
write_row_header(ba, ws, range, R);
if(dense && !row) continue;
var last_seen = false;
if(R <= range.e.r) for(var C = range.s.c; C <= range.e.c; ++C) {
/* *16384CELL */
if(R === range.s.r) cols[C] = encode_col(C);
ref = cols[C] + rr;
var cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) { last_seen = false; continue; }
/* write cell */
last_seen = write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904);
@ -19695,7 +19753,13 @@ function write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr){
var t = "", p = "";
switch(cell.t) {
case 'z': if(!opts.sheetStubs) return ""; break;
case 'n': t = 'Number'; p = String(cell.v); break;
case 'n': {
if(!isFinite(cell.v)) {
t = 'Error'; p = BErr[isNaN(cell.v) ? 0x24 : 0x07];
} else {
t = 'Number'; p = String(cell.v);
}
} break;
case 'b': t = 'Boolean'; p = (cell.v ? "1" : "0"); break;
case 'e': t = 'Error'; p = BErr[cell.v]; break;
case 'd': t = 'DateTime'; p = new Date(cell.v).toISOString(); if(cell.z == null) cell.z = cell.z || table_fmt[14]; break;
@ -19737,9 +19801,12 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
o.push(writextag("Column",null,k));
});
var dense = ws["!data"] != null;
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
@ -19750,7 +19817,6 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
break;
}
if(skip) continue;
var addr = {r:R,c:C};
var ref = encode_col(C) + encode_row(R), cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr));
}
@ -19774,7 +19840,7 @@ function write_ws_xlml(idx, opts, wb) {
/* WorksheetOptions */
o.push(write_ws_xlml_wsopts(ws, opts, idx, wb));
if(ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
if(ws && ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
return o.join("");
}
@ -19793,11 +19859,10 @@ function write_xlml(wb, opts) {
d.push(write_props_xlml(wb, opts));
d.push(write_wb_xlml(wb, opts));
d.push("");
d.push("");
d.push(write_names_xlml(wb, opts));
for(var i = 0; i < wb.SheetNames.length; ++i)
d.push(writextag("Worksheet", write_ws_xlml(i, opts, wb), {"ss:Name":escapexml(wb.SheetNames[i])}));
d[2] = write_sty_xlml(wb, opts);
d[3] = write_names_xlml(wb, opts);
return XML_HEADER + writextag("Workbook", d.join(""), {
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
@ -21978,7 +22043,7 @@ function write_ws_biff2(ba, ws, idx, opts, wb) {
if(range.e.c > 0xFF || range.e.r > 0x3FFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, 0x3FFF);
range.e.r = Math.min(range.e.r, 0x3FFF);
}
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
var row = [], comments = [];
@ -22387,9 +22452,9 @@ function write_ws_biff8(idx, opts, wb) {
var range = safe_decode_range(ws['!ref'] || "A1");
var MAX_ROWS = b8 ? 65536 : 16384;
if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV" + MAX_ROWS);
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, MAX_ROWS-1);
range.e.r = Math.min(range.e.r, MAX_ROWS-1);
}
write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
@ -22424,12 +22489,11 @@ function write_ws_biff8(idx, opts, wb) {
if(dense) row = ws["!data"][R] || [];
rr = encode_row(R);
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var cell = dense ? row[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) continue;
/* write cell */
write_ws_biff8_cell(ba, cell, R, C, opts, date1904);
if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
if(b8 && cell.l) ws['!links'].push([cols[C] + rr, cell.l]);
if(cell.c) comments.push([cell.c, R, C]);
}
}
@ -22573,6 +22637,9 @@ function write_biff_buf(wb, opts) {
if(range.e.c > 255) { // note: 255 is IV
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
if(range.e.r > 65535) {
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond row 65536. Data may be lost.");
}
}
var o = opts || {};
@ -22632,6 +22699,8 @@ function html_to_sheet(str, _opts) {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -22659,6 +22728,10 @@ function make_html_row(ws, r, R, o) {
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({});
@ -22769,6 +22842,7 @@ function sheet_add_dom(ws, table, _opts) {
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -22777,7 +22851,7 @@ function sheet_add_dom(ws, table, _opts) {
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -23078,7 +23152,7 @@ function parse_content_xml(d, _opts, _nfm) {
var Sheets = {}, SheetNames = [];
var ws = ({}); if(opts.dense) ws["!data"] = [];
var Rn, q;
var ctag = ({value:""});
var ctag = ({value:""}), ctag2 = ({});
var textp = "", textpidx = 0, textptag, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -23172,6 +23246,7 @@ function parse_content_xml(d, _opts, _nfm) {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({});
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null});
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -23225,6 +23300,9 @@ function parse_content_xml(d, _opts, _nfm) {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -23888,9 +23966,22 @@ var write_content_ods = /* @__PURE__ */(function() {
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -27127,6 +27218,8 @@ function readSync(data, opts) {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -27482,7 +27575,7 @@ function sheet_to_json(sheet, opts) {
}
var qreg = /"/g;
function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
function make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o) {
var isempty = true;
var row = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -27495,7 +27588,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -27522,7 +27615,7 @@ function sheet_to_csv(sheet, opts) {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -27537,7 +27630,7 @@ function sheet_to_txt(sheet, opts) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet) {
function sheet_to_formulae(sheet, opts) {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols = [], C;
@ -27558,6 +27651,7 @@ function sheet_to_formulae(sheet) {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";
@ -27826,7 +27920,7 @@ function write_csv_stream(sheet, opts) {
while(R <= r.e.r) {
++R;
if ((rowinfo[R-1]||{}).hidden) continue;
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, w, o);
if(row != null) {
if(row || (o.blankrows !== false)) return stream.push((w++ ? RS : "") + row);
}
@ -27923,10 +28017,165 @@ function write_json_stream(sheet, opts) {
return stream;
}
function write_xlml_stream(wb, o) {
var stream = _Readable();
var opts = o == null ? {} : o;
var stride = +opts.stride || 10;
if(!wb.SSF) wb.SSF = dup(table_fmt);
if(wb.SSF) {
make_ssf(); SSF_load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
}
/* do one pass to determine styles since they must be added before tables */
wb.SheetNames.forEach(function(n) {
var ws = wb.Sheets[n];
if(!ws || !ws["!ref"]) return;
var range = decode_range(ws["!ref"]);
var dense = ws["!data"] != null;
var ddata = dense ? ws["!data"] : [];
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
addr.r = R;
if(dense && !ddata[R]) continue;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var cell = dense ? ddata[R][C] : ws[encode_col(C) + encode_row(R)];
if(!cell) continue;
if(cell.t == "d" && cell.z == null) { cell = dup(cell); cell.z = table_fmt[14]; }
void get_cell_style(opts.cellXfs, cell, opts);
}
}
});
var sty = write_sty_xlml(wb, opts);
var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
stream._read = function() { switch(stage) {
/* header */
case 0: {
stage = 1;
stream.push(XML_HEADER);
stream.push("<Workbook" + wxt_helper({
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
'xmlns:x': XLMLNS.x,
'xmlns:ss': XLMLNS.ss,
'xmlns:dt': XLMLNS.dt,
'xmlns:html': XLMLNS.html
}) + ">");
} break;
/* preamble */
case 1: {
stage = 2;
stream.push(write_props_xlml(wb, opts));
stream.push(write_wb_xlml(wb, opts));
} break;
/* style and name tables */
case 2: {
stage = 3;
stream.push(sty);
stream.push(write_names_xlml(wb, opts));
} break;
/* worksheet preamble */
case 3: {
T = false;
if(wsidx >= wb.SheetNames.length) { stage = -1; stream.push(""); break; }
stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
ws = wb.Sheets[wb.SheetNames[wsidx]];
if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
var names = write_ws_xlml_names(ws, opts, wsidx, wb);
if(names.length) stream.push("<Names>" + names + "</Names>");
if(!ws["!ref"]) return (stage = 5);
range = safe_decode_range(ws["!ref"]);
R = range.s.r;
stage = 4;
} break;
/* worksheet intramble */
case 4: {
if(R < 0 || R > range.e.r) { if(T) stream.push("</Table>"); return void (stage = 5); }
if(R <= range.s.r) {
if(ws['!cols']) ws['!cols'].forEach(function(n, i) {
process_col(n);
var w = !!n.width;
var p = col_obj_w(i, n);
var k = {"ss:Index":i+1};
if(w) k['ss:Width'] = width2px(p.width);
if(n.hidden) k['ss:Hidden']="1";
if(!T) { T = true; stream.push("<Table>"); }
stream.push(writextag("Column",null,k));
});
dense = ws["!data"] != null;
if(dense) darr = ws["!data"];
addr.r = addr.c = 0;
}
/* undefined `stride` rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < stride; ++R, ++cnt) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
if(!(dense && !darr[R])) for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
if(marr[mi].s.r > R) continue;
if(marr[mi].e.c < C) continue;
if(marr[mi].e.r < R) continue;
if(marr[mi].s.c != C || marr[mi].s.r != R) skip = true;
break;
}
if(skip) continue;
var ref = encode_col(C) + encode_row(R), cell = dense ? darr[R][C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, wsidx, wb, addr));
}
row.push("</Row>");
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
} break;
/* worksheet postamble */
case 5: {
stream.push(write_ws_xlml_wsopts(ws, opts, wsidx, wb));
if(ws && ws["!autofilter"]) stream.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
stream.push("</Worksheet>");
wsidx++; R = -1;
return void (stage = 3);
}
/* footer */
case -1: {
stage = -2;
stream.push("</Workbook>");
} break;
/* exeunt */
case -2: stream.push(null); break;
}};
return stream;
}
var __stream = {
to_json: write_json_stream,
to_html: write_html_stream,
to_csv: write_csv_stream,
to_xlml: write_xlml_stream,
set_readable: set_readable
};
if(typeof parse_xlscfb !== "undefined") XLSX.parse_xlscfb = parse_xlscfb;

34
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

18
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

@ -49,6 +49,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;

@ -12,6 +12,7 @@ declare function a2s(a: any): string;
declare var has_buf: boolean;
declare function Base64_decode(s: string): string;
declare function fuzzynum(s: string): number;
declare var RBErr: {[key: string]: number};
function rtf_to_sheet(d: RawData, opts: ParsingOptions): WorkSheet {
switch(opts.type) {
@ -54,7 +55,7 @@ function rtf_to_sheet_str(str: string, opts: ParsingOptions): WorkSheet {
var cell: CellObject = {v: payload.join(""), t:"s"};
if(cell.v == "TRUE" || cell.v == "FALSE") { cell.v = cell.v == "TRUE"; cell.t = "b"; }
else if(!isNaN(fuzzynum(cell.v as string))) { cell.t = 'n'; if(o.cellText !== false) cell.w = cell.v as string; cell.v = fuzzynum(cell.v as string); }
else if(RBErr[cell.v as string] != null) { cell.t = "e"; cell.w = cell.v as string; cell.v = RBErr[cell.v as string]; }
if(dense) row[C] = cell;
else (ws as SparseSheet)[encode_cell({r:R, c:C})] = cell;
}

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.20.2",
"version": "0.20.2+strm",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [

@ -29,7 +29,7 @@ var general_fmt_num = (function make_general_fmt_num() {
}
function general_fmt_num_base(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#VALUE!" : "#DIV/0!";
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);

@ -42,7 +42,7 @@ function format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(isgeneral(f[1])) return general_fmt(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#VALUE!";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}

@ -254,7 +254,7 @@ var general_fmt_num = (function make_general_fmt_num() {
}
function general_fmt_num_base(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#VALUE!" : "#DIV/0!";
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -992,7 +992,7 @@ function format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(isgeneral(f[1])) return general_fmt(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#VALUE!";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}

@ -250,7 +250,7 @@ var general_fmt_num = (function make_general_fmt_num() {
}
function general_fmt_num_base(v) {
if(!isFinite(v)) return isNaN(v) ? "#VALUE!" : "#DIV/0!";
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -984,7 +984,7 @@ function format(fmt,v,o) {
if(isgeneral(f[1])) return general_fmt(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#VALUE!";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}

@ -23,10 +23,10 @@ describe('oddities', function() {
assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', NaN), " -");
assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', Infinity), " -");
assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', -Infinity), " -");
["0.00", "General"].forEach(function(fmt) {
["0.00", "General"].forEach(function(fmt) {
assert.equal(SSF.format(fmt, NaN), "#VALUE!");
assert.equal(SSF.format(fmt, Infinity), "#DIV/0!");
assert.equal(SSF.format(fmt, -Infinity), "#DIV/0!");
});
});
});
});

65
test.js

@ -54,7 +54,7 @@ if(!browser) {
for(var _fileAi = 0; _fileAi < _fileA.length; ++_fileAi) if(test_file(_fileA[_fileAi])) fileA.push(_fileA[_fileAi]);
}
var can_write_numbers = typeof Array.prototype.findIndex == "function" && typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.indexOf == "function";
var can_write_numbers = typeof Set !== "undefined" && typeof Array.prototype.findIndex == "function" && typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.indexOf == "function";
/* Excel enforces 31 character sheet limit, although technical file limit is 255 */
function fixsheetname(x/*:string*/)/*:string*/ { return x.substr(0,31); }
@ -800,6 +800,17 @@ describe('API', function() {
]);
if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' });
});
it('sheet_to_formulae', function() {
var ws = X.utils.aoa_to_sheet([
["a", "b", "c"],
[1, 2, 3],
[4, 5, 6]
], {dense: true});
ws["!data"][2][0].f = "2*B2";
ws["!data"][2][1].f = "B2+C2";
assert.equal(X.utils.sheet_to_formulae(ws).join("\n"), "A1='a\nB1='b\nC1='c\nA2=1\nB2=2\nC2=3\nA3=2*B2\nB3=B2+C2\nC3=6");
assert.equal(X.utils.sheet_to_formulae(ws, {values: false}).join("\n"), "A3=2*B2\nB3=B2+C2");
});
it('decode_range', function() {
var _c = "ABC", _r = "123", _C = "DEF", _R = "456";
@ -1889,6 +1900,32 @@ describe('roundtrip features', function() {
assert.ok(wb7.Workbook.WBProps.date1904);
}); });
it('should handle numeric NaN and Infinity', function() {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2176,7 +2213,7 @@ function plaintext_test(wb, raw) {
var sheet = wb.Sheets[wb.SheetNames[0]];
plaintext_val.forEach(function(x) {
var cell = get_cell(sheet, x[0]);
var tcval = x[2+(raw ? 1 : 0)];
var tcval = x[2+(!!raw ? 1 : 0)];
var type = raw ? 's' : x[1];
if(x.length == 1) { if(cell) { assert.equal(cell.t, 'z'); assert.ok(!cell.v); } return; }
assert.equal(cell.v, tcval); assert.equal(cell.t, type);
@ -2668,6 +2705,30 @@ describe('HTML', function() {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) it('should handle numeric NaN and Infinity', function() {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
describe('js -> file -> js', function() {

186
test.mjs generated

@ -371,13 +371,13 @@ if(!browser) describe('should parse test files', function() {
});
function get_cell(ws/*:Worksheet*/, addr/*:string*/) {
if(!Array.isArray(ws)) return ws[addr];
if(!ws["!data"]) return ws[addr];
var a = X.utils.decode_cell(addr);
return (ws[a.r]||[])[a.c];
return (ws["!data"][a.r]||[])[a.c];
}
function each_cell(ws, f) {
if(Array.isArray(ws)) ws.forEach(function(row) { if(row) row.forEach(f); });
if(ws["!data"]) ws["!data"].forEach(function(row) { if(row) row.forEach(f); });
else Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; f(ws[addr]); });
}
@ -804,6 +804,17 @@ describe('API', function() {
]);
if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' });
});
it('sheet_to_formulae', function() {
var ws = X.utils.aoa_to_sheet([
["a", "b", "c"],
[1, 2, 3],
[4, 5, 6]
], {dense: true});
ws["!data"][2][0].f = "2*B2";
ws["!data"][2][1].f = "B2+C2";
assert.equal(X.utils.sheet_to_formulae(ws).join("\n"), "A1='a\nB1='b\nC1='c\nA2=1\nB2=2\nC2=3\nA3=2*B2\nB3=B2+C2\nC3=6");
assert.equal(X.utils.sheet_to_formulae(ws, {values: false}).join("\n"), "A3=2*B2\nB3=B2+C2");
});
it('decode_range', function() {
var _c = "ABC", _r = "123", _C = "DEF", _R = "456";
@ -1027,10 +1038,14 @@ describe('parse features', function() {
});
describe('column properties', function() {
var wbs = [], wbs_no_slk = [];
var wbs = [], wbs_no_slk = [], ols = [];
var ol = fs.existsSync(paths.olxls);
var bef = (function() {
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); });
wbs_no_slk = wbs.slice(0, 5);
/* */
if(!ol) return;
ols = OLPaths.map(function(p) { return X.read(fs.readFileSync(p), {type:TYPE, cellStyles:true}); });
});
if(typeof before != 'undefined') before(bef);
else it('before', bef);
@ -1065,6 +1080,22 @@ describe('parse features', function() {
assert.equal(x[7].wpx, 101);
});
});
it('should have correct outline levels', function() {
ols.map(function(x) { return x.Sheets["Sheet1"]; }).forEach(function(ws) {
var cols = ws['!cols'];
if(!cols) return; // TODO: ODS!!!
for(var i = 0; i < 29; ++i) {
var cell = get_cell(ws, X.utils.encode_col(i) + "1");
var lvl = (cols[i]||{}).level||0;
if(!cell || cell.t == 's') assert.equal(lvl, 0);
else if(cell.t == 'n') {
if(cell.v === 0) assert.equal(lvl, 0);
else assert.equal(lvl, cell.v);
}
}
assert.equal(cols[29].level, 7);
});
});
});
describe('row properties', function() {
@ -1873,6 +1904,32 @@ describe('roundtrip features', function() {
assert.ok(wb7.Workbook.WBProps.date1904);
}); });
it('should handle numeric NaN and Infinity', function() {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2480,10 +2537,12 @@ describe('dbf', function() {
it(wbs[1][0], function() {
var wsfalse = wbsfalse[1][1].Sheets["Sheet1"];
[
["A1", "v", "CHAR10"], ["A2", "v", "test1"], ["B2", "v", 123.45], ["C2", "v", 12.345], ["D2", "v", 1234.1],
["A1", "v", "CHAR10"], ["A2", "v", "test1"], ["B2", "v", 123.45],
["C2", "v", 12.345], ["D2", "v", 1234.1],
["E2", "v", 6260], ["E2", "w", "19170219"],
["F2", "v", 6260], ["F2", "w", "19170219"],
["G2", "v", 1231.4], ["H2", "v", 123234], ["I2", "v", true], ["L2", "v", "SheetJS"]
["G2", "v", 1231.4], ["H2", "v", 123234],
["I2", "v", true], ["L2", "v", "SheetJS"]
].forEach(function(r) {
assert.equal(get_cell(wsfalse, r[0])[r[1]], r[2]);
});
@ -2649,6 +2708,30 @@ describe('HTML', function() {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) it('should handle numeric NaN and Infinity', function() {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
describe('js -> file -> js', function() {
@ -2706,6 +2789,97 @@ describe('rtf', function() {
});
});
describe('dense mode', function() {
it('sheet_new', function() {
var sp = X.utils.sheet_new(); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: false}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: true}); assert.ok(!!sp["!data"]);
});
it('read', function() {
ILPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.equal(ws["A1"].v, "Link to Sheet2");
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.equal(ws["!data"][0][0].v, "Link to Sheet2");
});
if(!browser) artifax.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(ws["A1"]);
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.ok(ws["!data"][0][0]);
});
});
it('aoa_to_sheet', function() {
var aoa = [["SheetJS"],[5433795]];
var sp = X.utils.aoa_to_sheet(aoa); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('json_to_sheet', function() {
var json = [{"SheetJS": 5433795}];
var sp = X.utils.json_to_sheet(json); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.json_to_sheet(json, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_aoa', function() {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_json', function() {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader:1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
ofmt.forEach(function(f) { it('write ' + f, function() {
var aoa = [["SheetJS"],[5433795]];
var wb = X.utils.book_new(X.utils.aoa_to_sheet(aoa));
var newwb = X.read(X.write(wb, {type:"binary", bookType:f}), {type:"binary"});
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A1").v, "SheetJS");
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A2").v, 5433795);
}); });
it('sheet_to_formulae', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_formulae(wb1.Sheets[n]).sort().join("\n"),
X.utils.sheet_to_formulae(wb2.Sheets[n]).sort().join("\n")
);
});
});
it('sheet_to_csv', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_csv(wb1.Sheets[n]),
X.utils.sheet_to_csv(wb2.Sheets[n])
);
});
});
});
describe('corner cases', function() {
it('output functions', function() {
var ws = X.utils.aoa_to_sheet([

164
test.mts

@ -388,9 +388,9 @@ describe('should parse test files', function() {
});
function get_cell(ws: X.WorkSheet, addr: string) {
if(!Array.isArray(ws)) return ws[addr];
if(!Array.isArray(ws["!data"])) return ws[addr];
var a = X.utils.decode_cell(addr);
return (ws[a.r]||[])[a.c];
return (ws["!data"][a.r]||[])[a.c];
}
function each_cell(ws: X.WorkSheet, f: (c: X.CellObject) => any) {
@ -1035,6 +1035,8 @@ describe('parse features', function() {
var wbs: X.WorkBook[] = [], wbs_no_slk: X.WorkBook[] = [];
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); });
wbs_no_slk = wbs.slice(0, 5);
/* */
var ols = OLPaths.map(function(p) { return X.read(fs.readFileSync(p), {type:TYPE, cellStyles:true}); });
it('should have "!cols"', function() {
wbs.forEach(function(wb) { assert.ok(wb.Sheets["Sheet1"]['!cols']); });
});
@ -1066,6 +1068,22 @@ describe('parse features', function() {
assert.equal(x?.[7].wpx, 101);
});
});
it('should have correct outline levels', function() {
ols.map(function(x) { return x.Sheets["Sheet1"]; }).forEach(function(ws) {
var cols = ws['!cols'];
if(!cols) return; // TODO: ODS!!!
for(var i = 0; i < 29; ++i) {
var cell = get_cell(ws, X.utils.encode_col(i) + "1");
var lvl = (cols[i]||{}).level||0;
if(!cell || cell.t == 's') assert.equal(lvl, 0);
else if(cell.t == 'n') {
if(cell.v === 0) assert.equal(lvl, 0);
else assert.equal(lvl, cell.v);
}
}
assert.equal(cols[29].level, 7);
});
});
});
describe('row properties', function() {
@ -1833,6 +1851,32 @@ describe('roundtrip features', function() {
assert.ok(wb7.Workbook?.WBProps?.date1904);
}); });
it('should handle numeric NaN and Infinity', function() {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws: X.DenseWorkSheet = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2585,6 +2629,30 @@ describe('HTML', function() {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) it('should handle numeric NaN and Infinity', function() {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
describe('js -> file -> js', function() {
@ -2638,6 +2706,98 @@ describe('rtf', function() {
});
});
describe('dense mode', function() {
it('sheet_new', function() {
var sp = X.utils.sheet_new(); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: false}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: true}); assert.ok(!!sp["!data"]);
});
it('read', function() {
ILPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.equal(ws["A1"].v, "Link to Sheet2");
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.equal(ws["!data"][0][0].v, "Link to Sheet2");
});
if(!browser) artifax.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(ws["A1"]);
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.ok(ws["!data"][0][0]);
});
});
it('aoa_to_sheet', function() {
var aoa = [["SheetJS"],[5433795]];
var sp = X.utils.aoa_to_sheet(aoa); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('json_to_sheet', function() {
var json = [{"SheetJS": 5433795}];
var sp = X.utils.json_to_sheet(json); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.json_to_sheet(json, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_aoa', function() {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_json', function() {
var aoa = [["SheetJS"]];
var sp: X.SparseSheet = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader:1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1}); assert.equal(ds["!data"]?.[1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(ds["!data"]?.[1][0].v, 5433795); assert.ok(!ds["A2"]);
});
for(var ofmti = 0; ofmti < ofmt.length; ++ofmti) { var f = ofmt[ofmti];
it('write ' + f, function() {
var aoa = [["SheetJS"],[5433795]];
var wb = X.utils.book_new(X.utils.aoa_to_sheet(aoa));
var newwb = X.read(X.write(wb, {type:"binary", bookType:f}), {type:"binary"});
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A1").v, "SheetJS");
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A2").v, 5433795);
}); }
it('sheet_to_formulae', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_formulae(wb1.Sheets[n]).sort().join("\n"),
X.utils.sheet_to_formulae(wb2.Sheets[n]).sort().join("\n")
);
});
});
it('sheet_to_csv', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_csv(wb1.Sheets[n]),
X.utils.sheet_to_csv(wb2.Sheets[n])
);
});
});
});
describe('corner cases', function() {
it('output functions', function() {
var ws = X.utils.aoa_to_sheet([

@ -40,5 +40,3 @@ for TZ in ${TZONES[@]}; do
env TZ="$TZ" WTF=1 make test-deno_misc;
env TZ="$TZ" WTF=1 make test-denocp_misc;
done

@ -1,10 +1,3 @@
var pdizzle = 0, fails = 0, passes = 0;
var describe = function(m,cb){console.log(" ".repeat(pdizzle) + m); ++pdizzle; if(cb) cb(); --pdizzle; };
describe.skip = function(m,cb){};
var it = function(m,cb){console.log(" ".repeat(pdizzle) + m); ++pdizzle; if(cb) try { cb(); ++passes } catch(e) { ++fails, console.log("\x1b[31mFAILED: " + (e.message || e) + "\x1b[0m"); } --pdizzle;};
it.skip = function(m,cb){};
var before = function(cb){if(cb) cb();};
var afterEach = function(cb){if(cb) cb();};
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*jshint mocha:true */
@ -43,7 +36,7 @@ if(typeof Buffer !== 'undefined') {
}
var opts = ({cellNF: true}/*:any*/);
var TYPE = browser ? "buffer" : "buffer";
var TYPE = browser ? "binary" : "buffer";
opts.type = TYPE;
var fullex = [".xlsb", /*".xlsm",*/ ".xlsx"/*, ".xlml", ".xls"*/];
var ofmt = ["xlsb", "xlsm", "xlsx", "ods", "biff2", "biff5", "biff8", "xlml", "sylk", "dif", "dbf", "eth", "fods", "csv", "txt", "html"];
@ -378,13 +371,13 @@ if(!browser) describe('should parse test files', function() {
});
function get_cell(ws/*:Worksheet*/, addr/*:string*/) {
if(!Array.isArray(ws)) return ws[addr];
if(!ws["!data"]) return ws[addr];
var a = X.utils.decode_cell(addr);
return (ws[a.r]||[])[a.c];
return (ws["!data"][a.r]||[])[a.c];
}
function each_cell(ws, f) {
if(Array.isArray(ws)) ws.forEach(function(row) { if(row) row.forEach(f); });
if(ws["!data"]) ws["!data"].forEach(function(row) { if(row) row.forEach(f); });
else Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; f(ws[addr]); });
}
@ -535,11 +528,11 @@ describe('parse options', function() {
"!ref": "A1:A1",
"A1": { t:"n", v:2, f:"_xlfn.IFS(2>3,1,3>2,2)"}
} } };
var str = X.write(wb, {bookType: "xlsx", type: "buffer"});
var wb2 = X.read(str, {type: "buffer"});
var str = X.write(wb, {bookType: "xlsx", type: "binary"});
var wb2 = X.read(str, {type: "binary"});
/*jshint -W069 */
assert.equal(wb2.Sheets["Sheet1"]["A1"].f, "IFS(2>3,1,3>2,2)");
var wb3 = X.read(str, {type: "buffer", xlfn: true});
var wb3 = X.read(str, {type: "binary", xlfn: true});
assert.equal(wb3.Sheets["Sheet1"]["A1"].f, "_xlfn.IFS(2>3,1,3>2,2)");
/*jshint +W069 */
});
@ -584,7 +577,7 @@ describe('parse options', function() {
checkcells(X.read(fs.readFileSync(p), {type:TYPE, sheetRows:10}), false, false, false, true);
}); });
it('sheetRows n=1', function() { ofmt.forEach(function(fmt) {
[TYPE, "buffer", "buffer", "array"].forEach(function(ot) {
[TYPE, "base64", "binary", "array"].forEach(function(ot) {
var data = [[1,2],[3,4],[5,6]];
var ws = X.utils.aoa_to_sheet(data);
assert.ok(ws['!ref'] === "A1:B3");
@ -688,10 +681,10 @@ describe('parse options', function() {
});
describe('input formats', function() {
if(false) it('should read binary strings', function() { artifax.forEach(function(p) {
it('should read binary strings', function() { artifax.forEach(function(p) {
X.read(fs.readFileSync(p, 'binary'), {type: 'binary'});
}); });
if(false) it('should read base64 strings', function() { artifax.forEach(function(p) {
it('should read base64 strings', function() { artifax.forEach(function(p) {
X.read(fs.readFileSync(p, 'base64'), {type: 'base64'});
}); });
it('handles base64 within data URI scheme (gh-2762)', function() {
@ -710,7 +703,7 @@ describe('input formats', function() {
assert.equal(get_cell(ws, "A3").v, "Sam");
});
});
if(false) if(typeof Uint8Array !== 'undefined') it('should read array', function() { artifax.forEach(function(p) {
if(typeof Uint8Array !== 'undefined') it('should read array', function() { artifax.forEach(function(p) {
X.read(fs.readFileSync(p, 'binary').split("").map(function(x) { return x.charCodeAt(0); }), {type:'array'});
}); });
((browser || typeof Buffer === 'undefined') ? it.skip : it)('should read Buffers', function() { artifax.forEach(function(p) {
@ -811,6 +804,17 @@ describe('API', function() {
]);
if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' });
});
it('sheet_to_formulae', function() {
var ws = X.utils.aoa_to_sheet([
["a", "b", "c"],
[1, 2, 3],
[4, 5, 6]
], {dense: true});
ws["!data"][2][0].f = "2*B2";
ws["!data"][2][1].f = "B2+C2";
assert.equal(X.utils.sheet_to_formulae(ws).join("\n"), "A1='a\nB1='b\nC1='c\nA2=1\nB2=2\nC2=3\nA3=2*B2\nB3=B2+C2\nC3=6");
assert.equal(X.utils.sheet_to_formulae(ws, {values: false}).join("\n"), "A3=2*B2\nB3=B2+C2");
});
it('decode_range', function() {
var _c = "ABC", _r = "123", _C = "DEF", _R = "456";
@ -1034,10 +1038,14 @@ describe('parse features', function() {
});
describe('column properties', function() {
var wbs = [], wbs_no_slk = [];
var wbs = [], wbs_no_slk = [], ols = [];
var ol = fs.existsSync(paths.olxls);
var bef = (function() {
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); });
wbs_no_slk = wbs.slice(0, 5);
/* */
if(!ol) return;
ols = OLPaths.map(function(p) { return X.read(fs.readFileSync(p), {type:TYPE, cellStyles:true}); });
});
if(typeof before != 'undefined') before(bef);
else it('before', bef);
@ -1072,6 +1080,22 @@ describe('parse features', function() {
assert.equal(x[7].wpx, 101);
});
});
it('should have correct outline levels', function() {
ols.map(function(x) { return x.Sheets["Sheet1"]; }).forEach(function(ws) {
var cols = ws['!cols'];
if(!cols) return; // TODO: ODS!!!
for(var i = 0; i < 29; ++i) {
var cell = get_cell(ws, X.utils.encode_col(i) + "1");
var lvl = (cols[i]||{}).level||0;
if(!cell || cell.t == 's') assert.equal(lvl, 0);
else if(cell.t == 'n') {
if(cell.v === 0) assert.equal(lvl, 0);
else assert.equal(lvl, cell.v);
}
}
assert.equal(cols[29].level, 7);
});
});
});
describe('row properties', function() {
@ -1267,8 +1291,8 @@ describe('parse features', function() {
if(typeof before != 'undefined') before(bef);
else it('before', bef);
['xlsx', 'xlsb'].forEach(function(m) { it(m, function() {
var bstr = X.write(wb, {type: "buffer", bookType: m});
var nwb = X.read(bstr, {type: "buffer"});
var bstr = X.write(wb, {type: "binary", bookType: m});
var nwb = X.read(bstr, {type: "binary"});
assert.equal(nwb.Workbook.WBProps.CodeName, wb.Workbook.WBProps.CodeName);
}); });
});
@ -1506,7 +1530,7 @@ describe('write features', function() {
var sheet = X.utils.aoa_to_sheet([["abc"]]);
get_cell(sheet, "A1").h = "<b>abc</b>";
var wb = {SheetNames:["Sheet1"], Sheets:{Sheet1:sheet}};
var str = X.write(wb, {bookType:"html", type:"buffer"});
var str = X.write(wb, {bookType:"html", type:"binary"});
assert.ok(str.indexOf("<b>abc</b>") > 0);
});
});
@ -1613,7 +1637,7 @@ function parseDate(str/*:string*/, date1904/*:boolean*/)/*:Date*/ {
var fixdate = browser ? parseDate("2014-02-19T14:30:00.000Z") : new Date("2014-02-19T14:30Z");
if(false) describe('roundtrip features', function() {
describe('roundtrip features', function() {
describe('should preserve core properties', function() { [
['xls', paths.cpxls],
['xlml', paths.cpxml],
@ -1734,7 +1758,7 @@ if(false) describe('roundtrip features', function() {
['xlsb', paths.pmxlsb]
].forEach(function(w) { it(w[0], function() {
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE});
var wb2 = X.read(X.write(wb1, {bookType:w[0], type:"buffer"}), {type:"buffer"});
var wb2 = X.read(X.write(wb1, {bookType:w[0], type:"binary"}), {type:"binary"});
[
/* Sheet Name Margins: left right top bottom head foot */
["Normal", [0.70, 0.70, 0.75, 0.75, 0.30, 0.30]],
@ -1880,6 +1904,32 @@ if(false) describe('roundtrip features', function() {
assert.ok(wb7.Workbook.WBProps.date1904);
}); });
it('should handle numeric NaN and Infinity', function() {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -1888,7 +1938,7 @@ var password_files = [
"password_2002_40_xor.xls"
];
describe('invalid files', function() {
if(false) describe('parse', function() { [
describe('parse', function() { [
['KEY files', 'numbers/Untitled.key'],
['PAGES files', 'numbers/Untitled.pages'],
['password', 'apachepoi_password.xls'],
@ -2187,21 +2237,18 @@ var html_bstr = make_html_str(1), html_str = make_html_str(0);
var csv_bstr = make_csv_str(1), csv_str = make_csv_str(0);
// WTF=1 make test-bun_misc in bun 1.0.15 reached this point
console.log(`${fails} FAILED ${passes} PASSED`); process.exit(+!!(fails > 0));
describe('CSV', function() {
describe('input', function(){
var b = "1,2,3,\nTRUE,FALSE,,sheetjs\nfoo,bar,2/19/14,0.3\n,,,\nbaz,,qux,\n";
it('should generate date numbers by default', function() {
var opts = {type:"buffer"};
var opts = {type:"binary"};
var cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.w, '2/19/14');
assert.equal(cell.t, 'n');
assert.ok(typeof cell.v == "number");
});
it('should generate dates when requested', function() {
var opts = {type:"buffer", cellDates:true};
var opts = {type:"binary", cellDates:true};
var cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.w, '2/19/14');
assert.equal(cell.t, 'd');
@ -2209,7 +2256,7 @@ describe('CSV', function() {
});
it('should use US date code 14 by default', function() {
var opts = ({type:"buffer"}/*:any*/);
var opts = ({type:"binary"}/*:any*/);
var cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.w, '2/19/14');
opts.cellDates = true;
@ -2217,7 +2264,7 @@ describe('CSV', function() {
assert.equal(cell.w, '2/19/14');
});
it('should honor dateNF override', function() {
var opts = ({type:"buffer", dateNF:"YYYY-MM-DD", cellNF: true}/*:any*/);
var opts = ({type:"binary", dateNF:"YYYY-MM-DD", cellNF: true}/*:any*/);
var cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
/* NOTE: IE interprets 2-digit years as 19xx */
assert.ok(cell.w == '2014-02-19' || cell.w == '1914-02-19' || cell.w == "2/19/14");
@ -2225,7 +2272,7 @@ describe('CSV', function() {
opts.cellDates = true; opts.dateNF = "YY-MM-DD";
cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
assert.ok(cell.w == '14-02-19' || cell.w == "2/19/14");
var opts = ({type:"buffer", dateNF:"YYYY-MM-DD", UTC: true}/*:any*/);
var opts = ({type:"binary", dateNF:"YYYY-MM-DD", UTC: true}/*:any*/);
var cell = get_cell(X.read(b, opts).Sheets["Sheet1"], "C3");
/* NOTE: IE interprets 2-digit years as 19xx */
assert.ok(cell.w == '2014-02-19' || cell.w == '1914-02-19');
@ -2235,7 +2282,7 @@ describe('CSV', function() {
});
it('should interpret dateNF', function() {
var bb = "1,2,3,\nTRUE,FALSE,,sheetjs\nfoo,bar,2/3/14,0.3\n,,,\nbaz,,qux,\n";
var opts = {type:"buffer", cellDates:true, dateNF:'m/d/yy'};
var opts = {type:"binary", cellDates:true, dateNF:'m/d/yy'};
var cell = get_cell(X.read(bb, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.v.getMonth(), 1);
assert.equal(cell.w, "2/3/14");
@ -2243,7 +2290,7 @@ describe('CSV', function() {
cell = get_cell(X.read(bb, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.v.getMonth(), 2);
assert.equal(cell.w, "2/3/14");
opts = {type:"buffer", cellDates:true, dateNF:'m/d/yy', UTC: true};
opts = {type:"binary", cellDates:true, dateNF:'m/d/yy', UTC: true};
cell = get_cell(X.read(bb, opts).Sheets["Sheet1"], "C3");
assert.equal(cell.v.getUTCMonth(), 1);
assert.equal(cell.w, "2/3/14");
@ -2252,11 +2299,11 @@ describe('CSV', function() {
assert.equal(cell.v.getUTCMonth(), 2);
assert.equal(cell.w, "2/3/14");
});
it('should interpret values by default', function() { plaintext_test(X.read(csv_bstr, {type:"buffer"}), false); });
it('should interpret values by default', function() { plaintext_test(X.read(csv_bstr, {type:"binary"}), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(csv_str, {type:"string", raw:true}), true); });
it('should handle formulae', function() {
var bb = '=,=1+1,="100"';
var sheet = X.read(bb, {type:"buffer"}).Sheets["Sheet1"];
var sheet = X.read(bb, {type:"binary"}).Sheets["Sheet1"];
assert.equal(get_cell(sheet, "A1").t, 's');
assert.equal(get_cell(sheet, "A1").v, '=');
assert.equal(get_cell(sheet, "B1").f, '1+1');
@ -2270,7 +2317,7 @@ describe('CSV', function() {
if(!browser || typeof cptable !== 'undefined') it('should honor codepage for binary strings', function() {
var data = "abc,def\nghi,j\xD3l";
[[1251, 'У'],[1252, 'Ó'], [1253, 'Σ'], [1254, 'Ó'], [1255, '׃'], [1256, 'س'], [10000, '”']].forEach(function(m) {
var ws = X.read(data, {type:"buffer", codepage:m[0]}).Sheets["Sheet1"];
var ws = X.read(data, {type:"binary", codepage:m[0]}).Sheets["Sheet1"];
assert.equal(get_cell(ws, "B2").v, "j" + m[1] + "l");
});
});
@ -2280,7 +2327,8 @@ describe('CSV', function() {
["3b", "3 b", "3 b-1"],
["3p", "3 P", "3 p-1"]
];
var ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true}).Sheets.Sheet1;
var ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true, UTC: false}).Sheets.Sheet1;
for(var R = 0; R < 3; ++R) {
assert.equal(get_cell(ws, "A" + (R+1)).v, aoa[R][0]);
assert.equal(get_cell(ws, "C" + (R+1)).v, aoa[R][2]);
@ -2288,15 +2336,12 @@ describe('CSV', function() {
assert.equal(get_cell(ws, "B2").v, "3 b");
var B1 = get_cell(ws, "B1"); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
var B3 = get_cell(ws, "B3"); assert.equal(B3.t, "d"); assert.equal(B3.v.getHours(), 15);
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: false}).Sheets.Sheet1;
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: false, UTC: false}).Sheets.Sheet1;
for(var R = 0; R < 3; ++R) {
assert.equal(get_cell(ws, "A" + (R+1)).v, aoa[R][0]);
assert.equal(get_cell(ws, "C" + (R+1)).v, aoa[R][2]);
}
assert.equal(get_cell(ws, "B2").v, "3 b");
/* this particular case is not well-defined */
//var B1 = get_cell(ws, "B1"); assert.equal(B1.t, "n"); assert.equal((24 + Math.round(B1.v * 24)) % 24, Math.round(3 + 24 + new Date(1899,11,31,0,0,0,0).getTimezoneOffset()/60) % 24);
//var B3 = get_cell(ws, "B3"); assert.equal(B3.t, "n"); assert.equal((24 + Math.round(B3.v * 24)) % 24, Math.round(15 + 24 + new Date(1899,11,31,0,0,0,0).getTimezoneOffset()/60) % 24);
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true, UTC: true}).Sheets.Sheet1;
for(var R = 0; R < 3; ++R) {
@ -2426,24 +2471,24 @@ describe('sylk', function() {
it('codepage', cpavail ? function() {
var str = "ID;PWXL;N;E\r\nC;X1;Y1;K\"a b\"\r\nE", A1 = "a b";
assert.equal(get_cell(X.read(str, {type:"string"}).Sheets["Sheet1"], "A1").v, A1);
assert.equal(get_cell(X.read(str.replace(//, "\x96"), {type:"buffer", codepage:1252}).Sheets["Sheet1"], "A1").v, A1);
assert.equal(get_cell(X.read(str.replace(//, "\x96"), {type:"binary", codepage:1252}).Sheets["Sheet1"], "A1").v, A1);
if(typeof Buffer !== 'undefined' && !browser) {
assert.equal(get_cell(X.read(Buffer_from(str), {type:"buffer", codepage:65001}).Sheets["Sheet1"], "A1").v, A1);
assert.equal(get_cell(X.read(Buffer_from(str.replace(//, "\x96"), "buffer"), {type:"buffer", codepage:1252}).Sheets["Sheet1"], "A1").v, A1);
assert.equal(get_cell(X.read(Buffer_from(str.replace(//, "\x96"), "binary"), {type:"buffer", codepage:1252}).Sheets["Sheet1"], "A1").v, A1);
}
} : null);
});
describe('date system', function() {
function make_slk(d1904) { return "ID;PSheetJS\nP;Pd\\/m\\/yy\nP;Pd\\/m\\/yyyy\n" + (d1904 != null ? "O;D;V" + d1904 : "") + "\nF;P0;FG0G;X1;Y1\nC;K1\nE"; }
it('should default to 1900', function() {
assert.equal(get_cell(X.read(make_slk(), {type: "buffer"}).Sheets["Sheet1"], "A1").v, 1);
assert.ok(get_cell(X.read(make_slk(), {type: "buffer", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() < 1902);
assert.equal(get_cell(X.read(make_slk(5), {type: "buffer"}).Sheets["Sheet1"], "A1").v, 1);
assert.ok(get_cell(X.read(make_slk(5), {type: "buffer", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() < 1902);
assert.equal(get_cell(X.read(make_slk(), {type: "binary"}).Sheets["Sheet1"], "A1").v, 1);
assert.ok(get_cell(X.read(make_slk(), {type: "binary", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() < 1902);
assert.equal(get_cell(X.read(make_slk(5), {type: "binary"}).Sheets["Sheet1"], "A1").v, 1);
assert.ok(get_cell(X.read(make_slk(5), {type: "binary", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() < 1902);
});
it('should use 1904 when specified', function() {
assert.ok(get_cell(X.read(make_slk(1), {type: "buffer", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() > 1902);
assert.ok(get_cell(X.read(make_slk(4), {type: "buffer", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() > 1902);
assert.ok(get_cell(X.read(make_slk(1), {type: "binary", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() > 1902);
assert.ok(get_cell(X.read(make_slk(4), {type: "binary", cellDates: true}).Sheets["Sheet1"], "A1").v.getFullYear() > 1902);
});
});
});
@ -2481,25 +2526,32 @@ describe('dbf', function() {
['d11', dir + 'dbf/d11.dbf'],
['vfp3', dir + 'dbf/vfp3.dbf']
]/*:any*/);
var wbstrue = ([]);
var wbsfalse = ([]);
var wbstrue = ([]);
var bef = (function() {
wbsfalse = wbs.map(function(x) { return [x[0], X.read(fs.readFileSync(x[1]), { type:TYPE, UTC: false })]; });
wbstrue = wbs.map(function(x) { return [x[0], X.read(fs.readFileSync(x[1]), { type:TYPE, UTC: true })]; });
wbsfalse = wbs.map(function(x) { return [x[0], X.read(fs.readFileSync(x[1]), { type:TYPE, cellDates: false })]; });
wbstrue = wbs.map(function(x) { return [x[0], X.read(fs.readFileSync(x[1]), { type:TYPE, cellDates: true })]; });
});
if(typeof before != 'undefined') before(bef);
else it('before', bef);
it(wbs[1][0], function() {
var wstrue = wbstrue[1][1].Sheets["Sheet1"];
var wsfalse = wbsfalse[1][1].Sheets["Sheet1"];
[
["A1", "v", "CHAR10"], ["A2", "v", "test1"], ["B2", "v", 123.45], ["C2", "v", 12.345], ["D2", "v", 1234.1],
["E2", "w", "19170219", (new Date(1917,1,19).getTimezoneOffset() > 0 ? "19170218" : "19170219")],
["F2", "w", "19170219", (new Date(1917,1,19).getTimezoneOffset() > 0 ? "19170218" : "19170219")],
["G2", "v", 1231.4], ["H2", "v", 123234], ["I2", "v", true], ["L2", "v", "SheetJS"]
["A1", "v", "CHAR10"], ["A2", "v", "test1"], ["B2", "v", 123.45],
["C2", "v", 12.345], ["D2", "v", 1234.1],
["E2", "v", 6260], ["E2", "w", "19170219"],
["F2", "v", 6260], ["F2", "w", "19170219"],
["G2", "v", 1231.4], ["H2", "v", 123234],
["I2", "v", true], ["L2", "v", "SheetJS"]
].forEach(function(r) {
assert.equal(get_cell(wstrue, r[0])[r[1]], r[2]);
assert.equal(get_cell(wsfalse, r[0])[r[1]], r[3] || r[2]);
assert.equal(get_cell(wsfalse, r[0])[r[1]], r[2]);
});
var wstrue = wbstrue[1][1].Sheets["Sheet1"];
[
["E2", "v", Date.UTC(1917,1,19,0,0,0,0)], ["E2", "w", "19170219"],
["F2", "v", Date.UTC(1917,1,19,0,0,0,0)], ["F2", "w", "19170219"]
].forEach(function(r) {
assert.equal(get_cell(wstrue, r[0])[r[1]].valueOf(), r[2].valueOf());
});
});
if(!browser || typeof cptable !== 'undefined') it("Ś╫êëτ⌡ś and Š╫ěéτ⌡š", function() {
@ -2513,8 +2565,7 @@ describe('dbf', function() {
});
});
});
//import { JSDOM } from 'jsdom';
const JSDOM = void 0;
import { JSDOM } from 'jsdom';
var domtest = true;
var inserted_dom_elements = [];
@ -2539,8 +2590,8 @@ describe('HTML', function() {
inserted_dom_elements = [];
});
describe('input string', function() {
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"buffer"}), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"buffer", raw:true}), true); });
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"binary"}), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"binary", raw:true}), true); });
it('should handle "string" type', function() { plaintext_test(X.read(html_str, {type:"string"}), false); });
it('should handle newlines correctly', function() {
var table = "<table><tr><td>foo<br/>bar</td><td>baz</td></tr></table>";
@ -2657,10 +2708,34 @@ describe('HTML', function() {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) it('should handle numeric NaN and Infinity', function() {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
describe('js -> file -> js', function() {
var wb, BIN="buffer";
var wb, BIN="binary";
var bef = (function() {
var ws = X.utils.aoa_to_sheet([
["number", "bool", "string", "date"],
@ -2714,6 +2789,97 @@ describe('rtf', function() {
});
});
describe('dense mode', function() {
it('sheet_new', function() {
var sp = X.utils.sheet_new(); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: false}); assert.ok(!sp["!data"]);
sp = X.utils.sheet_new({dense: true}); assert.ok(!!sp["!data"]);
});
it('read', function() {
ILPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.equal(ws["A1"].v, "Link to Sheet2");
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.equal(ws["!data"][0][0].v, "Link to Sheet2");
});
if(!browser) artifax.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(ws["A1"]);
assert.ok(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.ok(!ws["A1"]);
assert.ok(ws["!data"][0][0]);
});
});
it('aoa_to_sheet', function() {
var aoa = [["SheetJS"],[5433795]];
var sp = X.utils.aoa_to_sheet(aoa); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('json_to_sheet', function() {
var json = [{"SheetJS": 5433795}];
var sp = X.utils.json_to_sheet(json); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.json_to_sheet(json, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_aoa', function() {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
it('sheet_add_json', function() {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader:1}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.ok(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.ok(!ds["A2"]);
});
ofmt.forEach(function(f) { it('write ' + f, function() {
var aoa = [["SheetJS"],[5433795]];
var wb = X.utils.book_new(X.utils.aoa_to_sheet(aoa));
var newwb = X.read(X.write(wb, {type:"binary", bookType:f}), {type:"binary"});
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A1").v, "SheetJS");
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A2").v, 5433795);
}); });
it('sheet_to_formulae', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_formulae(wb1.Sheets[n]).sort().join("\n"),
X.utils.sheet_to_formulae(wb2.Sheets[n]).sort().join("\n")
);
});
});
it('sheet_to_csv', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_csv(wb1.Sheets[n]),
X.utils.sheet_to_csv(wb2.Sheets[n])
);
});
});
});
describe('corner cases', function() {
it('output functions', function() {
var ws = X.utils.aoa_to_sheet([
@ -2731,13 +2897,13 @@ describe('corner cases', function() {
ws['!cols'] = [ {wch:6}, {wch:7}, {wch:10}, {wch:20} ];
var wb = {SheetNames:['sheetjs'], Sheets:{sheetjs:ws}};
X.write(wb, {type: "buffer", bookType: 'xlsx'});
X.write(wb, {type: "binary", bookType: 'xlsx'});
X.write(wb, {type: TYPE, bookType: 'xlsm'});
X.write(wb, {type: "base64", bookType: 'xlsb'});
X.write(wb, {type: "buffer", bookType: 'ods'});
X.write(wb, {type: "buffer", bookType: 'biff2'});
X.write(wb, {type: "buffer", bookType: 'biff5'});
X.write(wb, {type: "buffer", bookType: 'biff8'});
X.write(wb, {type: "binary", bookType: 'ods'});
X.write(wb, {type: "binary", bookType: 'biff2'});
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.sheet_to_json(ws); });
});
@ -2779,7 +2945,7 @@ describe('corner cases', function() {
}
var ws = X.utils.aoa_to_sheet(data);
var wb = { Sheets:{ Sheet1: ws }, SheetNames: ["Sheet1"] };
var type = "buffer";
var type = "binary";
["xlsb", "biff8", "biff5", "biff2"].forEach(function(btype) {
void X.read(X.write(wb, {bookType:btype, type:type}), {type:type});
});

164
test.ts

@ -388,9 +388,9 @@ Deno.test('should parse test files', async function(t) {
});
function get_cell(ws: X.WorkSheet, addr: string) {
if(!Array.isArray(ws)) return ws[addr];
if(!Array.isArray(ws["!data"])) return ws[addr];
var a = X.utils.decode_cell(addr);
return (ws[a.r]||[])[a.c];
return (ws["!data"][a.r]||[])[a.c];
}
function each_cell(ws: X.WorkSheet, f: (c: X.CellObject) => any) {
@ -1035,6 +1035,8 @@ Deno.test('parse features', async function(t) {
var wbs: X.WorkBook[] = [], wbs_no_slk: X.WorkBook[] = [];
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); });
wbs_no_slk = wbs.slice(0, 5);
/* */
var ols = OLPaths.map(function(p) { return X.read(fs.readFileSync(p), {type:TYPE, cellStyles:true}); });
await t.step('should have "!cols"', async function(t) {
wbs.forEach(function(wb) { assert.assert(wb.Sheets["Sheet1"]['!cols']); });
});
@ -1066,6 +1068,22 @@ Deno.test('parse features', async function(t) {
assert.equal(x?.[7].wpx, 101);
});
});
await t.step('should have correct outline levels', async function(t) {
ols.map(function(x) { return x.Sheets["Sheet1"]; }).forEach(function(ws) {
var cols = ws['!cols'];
if(!cols) return; // TODO: ODS!!!
for(var i = 0; i < 29; ++i) {
var cell = get_cell(ws, X.utils.encode_col(i) + "1");
var lvl = (cols[i]||{}).level||0;
if(!cell || cell.t == 's') assert.equal(lvl, 0);
else if(cell.t == 'n') {
if(cell.v === 0) assert.equal(lvl, 0);
else assert.equal(lvl, cell.v);
}
}
assert.equal(cols[29].level, 7);
});
});
});
await t.step('row properties', async function(t) {
@ -1833,6 +1851,32 @@ Deno.test('roundtrip features', async function(t) {
assert.assert(wb7.Workbook?.WBProps?.date1904);
}); });
await t.step('should handle numeric NaN and Infinity', async function(t) {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws: X.DenseWorkSheet = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2585,6 +2629,30 @@ Deno.test('HTML', async function(t) {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) await t.step('should handle numeric NaN and Infinity', async function(t) {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
Deno.test('js -> file -> js', async function(t) {
@ -2638,6 +2706,98 @@ Deno.test('rtf', async function(t) {
});
});
Deno.test('dense mode', async function(t) {
await t.step('sheet_new', async function(t) {
var sp = X.utils.sheet_new(); assert.assert(!sp["!data"]);
sp = X.utils.sheet_new({}); assert.assert(!sp["!data"]);
sp = X.utils.sheet_new({dense: false}); assert.assert(!sp["!data"]);
sp = X.utils.sheet_new({dense: true}); assert.assert(!!sp["!data"]);
});
await t.step('read', async function(t) {
ILPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.equal(ws["A1"].v, "Link to Sheet2");
assert.assert(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.assert(!ws["A1"]);
assert.equal(ws["!data"][0][0].v, "Link to Sheet2");
});
if(!browser) artifax.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true});
var ws = wb.Sheets[wb.SheetNames[0]];
assert.assert(ws["A1"]);
assert.assert(!ws["!data"]);
wb = X.read(fs.readFileSync(p), {type: TYPE, WTF: true, dense: true});
ws = wb.Sheets[wb.SheetNames[0]];
assert.assert(!ws["A1"]);
assert.assert(ws["!data"][0][0]);
});
});
await t.step('aoa_to_sheet', async function(t) {
var aoa = [["SheetJS"],[5433795]];
var sp = X.utils.aoa_to_sheet(aoa); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.assert(!ds["A2"]);
});
await t.step('json_to_sheet', async function(t) {
var json = [{"SheetJS": 5433795}];
var sp = X.utils.json_to_sheet(json); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.json_to_sheet(json, {dense: false}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
var ds = X.utils.json_to_sheet(json, {dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.assert(!ds["A2"]);
});
await t.step('sheet_add_aoa', async function(t) {
var aoa = [["SheetJS"]];
var sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_aoa(sp, [[5433795]], {origin:-1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1}); assert.equal(ds["!data"][1][0].v, 5433795); assert.assert(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_aoa(ds, [[5433795]], {origin:-1, dense: true}); assert.equal(ds["!data"][1][0].v, 5433795); assert.assert(!ds["A2"]);
});
await t.step('sheet_add_json', async function(t) {
var aoa = [["SheetJS"]];
var sp: X.SparseSheet = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader:1}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
sp = X.utils.aoa_to_sheet(aoa); X.utils.sheet_add_json(sp, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(sp["A2"].v, 5433795); assert.assert(!sp["!data"]);
var ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1}); assert.equal(ds["!data"]?.[1][0].v, 5433795); assert.assert(!ds["A2"]);
ds = X.utils.aoa_to_sheet(aoa, {dense: true}); X.utils.sheet_add_json(ds, [{X:5433795}], {origin:-1, skipHeader: 1, dense: true}); assert.equal(ds["!data"]?.[1][0].v, 5433795); assert.assert(!ds["A2"]);
});
for(var ofmti = 0; ofmti < ofmt.length; ++ofmti) { var f = ofmt[ofmti];
await t.step('write ' + f, async function(t) {
var aoa = [["SheetJS"],[5433795]];
var wb = X.utils.book_new(X.utils.aoa_to_sheet(aoa));
var newwb = X.read(X.write(wb, {type:"binary", bookType:f}), {type:"binary"});
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A1").v, "SheetJS");
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A2").v, 5433795);
}); }
await t.step('sheet_to_formulae', async function(t) {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_formulae(wb1.Sheets[n]).sort().join("\n"),
X.utils.sheet_to_formulae(wb2.Sheets[n]).sort().join("\n")
);
});
});
await t.step('sheet_to_csv', async function(t) {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_csv(wb1.Sheets[n]),
X.utils.sheet_to_csv(wb2.Sheets[n])
);
});
});
});
Deno.test('corner cases', async function(t) {
await t.step('output functions', async function(t) {
var ws = X.utils.aoa_to_sheet([

89
tests/core.js generated

@ -54,7 +54,7 @@ if(!browser) {
for(var _fileAi = 0; _fileAi < _fileA.length; ++_fileAi) if(test_file(_fileA[_fileAi])) fileA.push(_fileA[_fileAi]);
}
var can_write_numbers = typeof Array.prototype.findIndex == "function" && typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.indexOf == "function";
var can_write_numbers = typeof Set !== "undefined" && typeof Array.prototype.findIndex == "function" && typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.indexOf == "function";
/* Excel enforces 31 character sheet limit, although technical file limit is 255 */
function fixsheetname(x/*:string*/)/*:string*/ { return x.substr(0,31); }
@ -800,6 +800,17 @@ describe('API', function() {
]);
if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' });
});
it('sheet_to_formulae', function() {
var ws = X.utils.aoa_to_sheet([
["a", "b", "c"],
[1, 2, 3],
[4, 5, 6]
], {dense: true});
ws["!data"][2][0].f = "2*B2";
ws["!data"][2][1].f = "B2+C2";
assert.equal(X.utils.sheet_to_formulae(ws).join("\n"), "A1='a\nB1='b\nC1='c\nA2=1\nB2=2\nC2=3\nA3=2*B2\nB3=B2+C2\nC3=6");
assert.equal(X.utils.sheet_to_formulae(ws, {values: false}).join("\n"), "A3=2*B2\nB3=B2+C2");
});
it('decode_range', function() {
var _c = "ABC", _r = "123", _C = "DEF", _R = "456";
@ -1889,6 +1900,32 @@ describe('roundtrip features', function() {
assert.ok(wb7.Workbook.WBProps.date1904);
}); });
it('should handle numeric NaN and Infinity', function() {[
"xlsx", "xlsm", "xlsb", "xls", "biff5", "biff4", "biff3", "biff2", "xlml", "csv", "txt", "sylk", "html", "rtf", "prn", "eth", "ods", "fods"
].forEach(function(ext) {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var buf = X.write(wb, { type: TYPE, bookType: ext, numbers: XLSX_ZAHL });
var wb2 = X.read(buf, { type: TYPE, PRN: true });
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2176,7 +2213,7 @@ function plaintext_test(wb, raw) {
var sheet = wb.Sheets[wb.SheetNames[0]];
plaintext_val.forEach(function(x) {
var cell = get_cell(sheet, x[0]);
var tcval = x[2+(raw ? 1 : 0)];
var tcval = x[2+(!!raw ? 1 : 0)];
var type = raw ? 's' : x[1];
if(x.length == 1) { if(cell) { assert.equal(cell.t, 'z'); assert.ok(!cell.v); } return; }
assert.equal(cell.v, tcval); assert.equal(cell.t, type);
@ -2668,6 +2705,30 @@ describe('HTML', function() {
assert.equal(range.e.c, expectedCellCount - 1);
});
});
if(domtest) it('should handle numeric NaN and Infinity', function() {
var ws = {
"!data": [
[ { t: "s", v: "Inf+" }, { t: "n", v: Infinity } ],
[ { t: "s", v: "Inf-" }, { t: "n", v: -Infinity } ],
[ { t: "s", v: "NaN" }, { t: "n", v: NaN } ],
],
"!ref": "A1:B3"
};
var wb = X.utils.book_new(ws, "Sheet1");
var str = X.write(wb, { type: "string", bookType: "html" });
var wb2 = X.utils.table_to_book(get_dom_element(str));
var csv = X.utils.sheet_to_csv(wb2.Sheets.Sheet1).split(/[\r\n]+/);
assert.equal(csv.length, 3);
assert.equal(csv[0], "Inf+,#DIV/0!");
assert.equal(csv[1], "Inf-,#DIV/0!");
assert.equal(csv[2], "NaN,#NUM!");
assert.equal(wb2.Sheets.Sheet1.B1.t, "e");
assert.equal(wb2.Sheets.Sheet1.B2.t, "e");
assert.equal(wb2.Sheets.Sheet1.B3.t, "e");
assert.equal(wb2.Sheets.Sheet1.B1.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B2.v, 0x07);
assert.equal(wb2.Sheets.Sheet1.B3.v, 0x24);
});
});
describe('js -> file -> js', function() {
@ -2792,7 +2853,29 @@ describe('dense mode', function() {
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A1").v, "SheetJS");
assert.equal(get_cell(newwb.Sheets["Sheet1"], "A2").v, 5433795);
}); });
;});
it('sheet_to_formulae', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_formulae(wb1.Sheets[n]).sort().join("\n"),
X.utils.sheet_to_formulae(wb2.Sheets[n]).sort().join("\n")
);
});
});
it('sheet_to_csv', function() {
var w = ['xlsx', paths.fstxlsx];
var wb1 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: false});
var wb2 = X.read(fs.readFileSync(w[1]), {type:TYPE, cellFormula:true, WTF:true, dense: true});
wb1.SheetNames.forEach(function(n) {
assert.equal(
X.utils.sheet_to_csv(wb1.Sheets[n]),
X.utils.sheet_to_csv(wb2.Sheets[n])
);
});
});
});
describe('corner cases', function() {
it('output functions', function() {

2
tests/fixtures.js generated

File diff suppressed because one or more lines are too long

40
types/index.d.ts vendored

@ -836,6 +836,14 @@ export interface Sheet2JSONOpts extends DateNFOption {
UTC?: boolean;
}
export interface Sheet2FormulaOpts {
/**
* If false, only export cells with formulae.
* By default, synthetic formulae are generated for each cell.
*/
values?: boolean;
}
export interface UTCDateOption {
/**
* If true, dates are interpreted using the UTC methods
@ -934,7 +942,7 @@ export interface XLSX$Utils {
sheet_to_html(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
/** Generates a list of the formulae (with value fallbacks) */
sheet_to_formulae(worksheet: WorkSheet): string[];
sheet_to_formulae(worksheet: WorkSheet, options?: Sheet2FormulaOpts): string[];
/* --- Cell Address Utilities --- */
@ -1020,14 +1028,38 @@ export interface XLSX$Consts {
SHEET_VERYHIDDEN: 2;
}
/** NODE ONLY! these return Readable Streams */
export interface StrideOption {
/** Number of rows to write per step */
stride?: number;
}
export interface XLMLStreamOpts extends WritingOptions, StrideOption {}
/**
* Streaming write methods
*
* These methods are directly compatible with NodeJS `stream.Readable` API
*
* Web Streams (modern browsers) can play nice with NodeJS streams. See the Web
* Demo at https://docs.sheetjs.com/docs/demos/bigdata/worker#streaming-write
*
* NOTE: These methods are not included in the `xlsx.mini.min.js` build!
*/
export interface StreamUtils {
/** Set `Readable` (for environments that do not support NodeJS Streams) */
set_readable(Readable: any): void;
/* --- Worksheet writers --- */
/** CSV output stream, generate one line at a time */
to_csv(sheet: WorkSheet, opts?: Sheet2CSVOpts): any;
/** HTML output stream, generate one line at a time */
to_html(sheet: WorkSheet, opts?: Sheet2HTMLOpts): any;
/** JSON object stream, generate one row at a time */
to_json(sheet: WorkSheet, opts?: Sheet2JSONOpts): any;
/** Set `Readable` (internal) */
set_readable(Readable: any): void;
/* --- Workbook writers --- */
/** XLML output string stream (bookType `xlml`) */
to_xlml(data: WorkBook, opts?: XLMLStreamOpts): any;
}

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -559,6 +559,7 @@ function SSF_large_exp(v/*:number*/)/*:string*/ {
}
function SSF_general_num(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1256,6 +1257,8 @@ function choose_fmt(f/*:string*/, v/*:any*/) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1292,6 +1295,8 @@ function SSF_format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt/*:string*/, idx/*:?number*/)/*:number*/ {
@ -1451,7 +1456,9 @@ type CFBFiles = {[n:string]:CFBEntry};
var CRC32 = /*#__PURE__*/(function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*::
type CRC32TableType = Array<number> | Int32Array;
*/
/*global Int32Array */
function signed_crc_table()/*:any*/ {
var c = 0, table/*:Array<number>*/ = new Array(256);
@ -1489,7 +1496,7 @@ 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*/ {
function crc32_bstr(bstr/*:string*/, seed/*:?number*/)/*:number*/ {
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;
@ -2855,8 +2862,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2867,7 +2874,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; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2902,9 +2909,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3803,6 +3811,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3873,6 +3884,26 @@ function parsexmltag(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*
}
return z;
}
function parsexmltagraw(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*/)/*:any*/ {
var z = ({}/*:any*/);
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x/*:string*/)/*:string*/ { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4385,7 +4416,8 @@ function recordhopper(data, cb/*:RecordHopperCB*/, opts/*:?any*/) {
/* control buffer usage for fixed-length buffers */
function buf_array()/*:BufArray*/ {
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 256 : 2048;
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz/*:number*/)/*:Block*/ {
var o/*:Block*/ = (new_buf(sz)/*:any*/);
prep_blob(o, 0);
@ -4414,10 +4446,15 @@ function buf_array()/*:BufArray*/ {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs }/*:any*/);
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 }/*:any*/);
}
function write_record(ba/*:BufArray*/, type/*:number*/, payload, length/*:?number*/) {
@ -4609,7 +4646,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
var ws/*:Worksheet*/ = _ws || (dense ? ({"!data": []}) : ({}/*:any*/));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4634,31 +4671,35 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data_R[C], t:"" }/*:any*/);
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; /*# DIV/0 */ }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4672,7 +4713,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr/*:any*/;
var cell_ref = encode_col(__C) + (__R + 1)/*:any*/;
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4682,7 +4723,6 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
return ws;
}
function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_add_aoa(null, data, opts); }
function parse_Int32LE(data) {
return data.read_shift(4, 'i');
}
@ -6266,8 +6306,8 @@ function parse_TypedPropertyValue(blob, type/*:number*/, _opts)/*:any*/ {
case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
case 0x1E /*VT_LPSTR*/: return parse_lpstr(blob, t, 4).replace(chr0,'');
case 0x1F /*VT_LPWSTR*/: return parse_lpwstr(blob);
case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@ -8562,7 +8602,7 @@ var SYLK = /*#__PURE__*/(function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -8791,7 +8831,7 @@ var ETH = /*#__PURE__*/(function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -8834,11 +8874,7 @@ var ETH = /*#__PURE__*/(function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -8848,6 +8884,19 @@ var ETH = /*#__PURE__*/(function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -8879,6 +8928,7 @@ var PRN = /*#__PURE__*/(function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -8996,6 +9046,8 @@ var PRN = /*#__PURE__*/(function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -9695,7 +9747,6 @@ var WK_ = /*#__PURE__*/(function() {
else console.error("WK1 bad formula parse |" + out.join("|") + "|");
}
function parse_cell_3(blob/*::, length*/) {
var o = [{c:0,r:0}, {t:'n',v:0}, 0];
o[0].r = blob.read_shift(2); o[3] = blob[blob.l++]; o[0].c = blob[blob.l++];
@ -10931,6 +10982,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;
@ -11323,6 +11378,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -15855,7 +15911,7 @@ function parse_ws_xml(data/*:?string*/, opts, idx/*:number*/, rels, wb/*:WBWBPro
var merges/*:Array<Range>*/ = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -16314,16 +16370,17 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th
function write_ws_xml_data(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbook*//*::, rels*/)/*:string*/ {
var o/*:Array<string>*/ = [], r/*:Array<string>*/ = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols/*:Array<string>*/ = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}/*:any*/), row/*:RowInfo*/, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -17325,12 +17382,15 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) {
if(last_seen) write_record(ba, 0x000D /* BrtShortRk */, write_BrtShortRk(cell, o));
else write_record(ba, 0x0002 /* BrtCellRk */, write_BrtCellRk(cell, o));
} else if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else if(!isFinite(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
o.t = "e";
if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
}
} else {
if(last_seen) write_record(ba, 0x0010 /* BrtShortReal */, write_BrtShortReal(cell, o));
else write_record(ba, 0x0005 /* BrtCellReal */, write_BrtCellReal(cell, o));
@ -17352,23 +17412,24 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
}
function write_CELLTABLE(ba, ws/*:Worksheet*/, idx/*:number*/, opts, wb/*:Workbook*/) {
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols/*:Array<string>*/ = [];
var range = safe_decode_range(ws['!ref'] || "A1"), rr = "", cols/*:Array<string>*/ = [];
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
write_record(ba, 0x0091 /* BrtBeginSheetData */);
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, row = dense ? ws["!data"][range.s.r] : [];
var cap = range.e.r;
if(ws['!rows']) cap = Math.max(range.e.r, ws['!rows'].length - 1);
for(var R = range.s.r; R <= cap; ++R) {
rr = encode_row(R);
if(dense) row = ws["!data"][R];
/* [ACCELLTABLE] */
/* BrtRowHdr */
write_row_header(ba, ws, range, R);
if(dense && !row) continue;
var last_seen = false;
if(R <= range.e.r) for(var C = range.s.c; C <= range.e.c; ++C) {
/* *16384CELL */
if(R === range.s.r) cols[C] = encode_col(C);
ref = cols[C] + rr;
var cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) { last_seen = false; continue; }
/* write cell */
last_seen = write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904);
@ -19640,7 +19701,13 @@ function write_ws_xlml_cell(cell, ref/*:string*/, ws, opts, idx/*:number*/, wb,
var t = "", p = "";
switch(cell.t) {
case 'z': if(!opts.sheetStubs) return ""; break;
case 'n': t = 'Number'; p = String(cell.v); break;
case 'n': {
if(!isFinite(cell.v)) {
t = 'Error'; p = BErr[isNaN(cell.v) ? 0x24 : 0x07];
} else {
t = 'Number'; p = String(cell.v);
}
} break;
case 'b': t = 'Boolean'; p = (cell.v ? "1" : "0"); break;
case 'e': t = 'Error'; p = BErr[cell.v]; break;
case 'd': t = 'DateTime'; p = new Date(cell.v).toISOString(); if(cell.z == null) cell.z = cell.z || table_fmt[14]; break;
@ -19682,9 +19749,12 @@ function write_ws_xlml_table(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbo
o.push(writextag("Column",null,k));
});
var dense = ws["!data"] != null;
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
@ -19695,7 +19765,6 @@ function write_ws_xlml_table(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbo
break;
}
if(skip) continue;
var addr = {r:R,c:C};
var ref = encode_col(C) + encode_row(R), cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr));
}
@ -19719,7 +19788,7 @@ function write_ws_xlml(idx/*:number*/, opts, wb/*:Workbook*/)/*:string*/ {
/* WorksheetOptions */
o.push(write_ws_xlml_wsopts(ws, opts, idx, wb));
if(ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
if(ws && ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
return o.join("");
}
@ -19738,11 +19807,10 @@ function write_xlml(wb, opts)/*:string*/ {
d.push(write_props_xlml(wb, opts));
d.push(write_wb_xlml(wb, opts));
d.push("");
d.push("");
d.push(write_names_xlml(wb, opts));
for(var i = 0; i < wb.SheetNames.length; ++i)
d.push(writextag("Worksheet", write_ws_xlml(i, opts, wb), {"ss:Name":escapexml(wb.SheetNames[i])}));
d[2] = write_sty_xlml(wb, opts);
d[3] = write_names_xlml(wb, opts);
return XML_HEADER + writextag("Workbook", d.join(""), {
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
@ -21928,7 +21996,7 @@ function write_ws_biff2(ba/*:BufArray*/, ws/*:Worksheet*/, idx/*:number*/, opts,
if(range.e.c > 0xFF || range.e.r > 0x3FFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, 0x3FFF);
range.e.r = Math.min(range.e.r, 0x3FFF);
}
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
var row = [], comments = [];
@ -22338,9 +22406,9 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) {
var range = safe_decode_range(ws['!ref'] || "A1");
var MAX_ROWS = b8 ? 65536 : 16384;
if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV" + MAX_ROWS);
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, MAX_ROWS-1);
range.e.r = Math.min(range.e.r, MAX_ROWS-1);
}
write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
@ -22375,12 +22443,11 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) {
if(dense) row = ws["!data"][R] || [];
rr = encode_row(R);
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var cell = dense ? row[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) continue;
/* write cell */
write_ws_biff8_cell(ba, cell, R, C, opts, date1904);
if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
if(b8 && cell.l) ws['!links'].push([cols[C] + rr, cell.l]);
if(cell.c) comments.push([cell.c, R, C]);
}
}
@ -22524,6 +22591,9 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(range.e.c > 255) { // note: 255 is IV
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
if(range.e.r > 65535) {
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond row 65536. Data may be lost.");
}
}
var o = opts || {};
@ -22583,6 +22653,8 @@ function html_to_sheet(str/*:string*/, _opts)/*:Workbook*/ {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -22610,6 +22682,10 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({}/*:any*/);
@ -22720,6 +22796,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -22728,7 +22805,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -23029,7 +23106,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
var Sheets = {}, SheetNames/*:Array<string>*/ = [];
var ws = ({}/*:any*/); if(opts.dense) ws["!data"] = [];
var Rn, q/*:: :any = ({t:"", v:null, z:null, w:"",c:[],}:any)*/;
var ctag = ({value:""}/*:any*/);
var ctag = ({value:""}/*:any*/), ctag2 = ({}/*:any*/);
var textp = "", textpidx = 0, textptag/*:: = {}*/, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -23123,6 +23200,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({}/*:any*/);
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null/*:: , z:null, w:"",c:[]*/}/*:any*/);
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -23176,6 +23254,9 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -23839,9 +23920,22 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = /* @__PURE__ */(function
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -27082,6 +27176,8 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -27444,7 +27540,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) {
}
var qreg = /"/g;
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, w/*:number*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
var isempty = true;
var row/*:Array<string>*/ = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -27457,7 +27553,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -27484,7 +27580,7 @@ function sheet_to_csv(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/)/*:string*/ {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -27499,7 +27595,7 @@ function sheet_to_txt(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
function sheet_to_formulae(sheet/*:Worksheet*/, opts/*:?Sheet2FormulaOpts*/)/*:Array<string>*/ {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols/*:Array<string>*/ = [], C;
@ -27520,6 +27616,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";
@ -27788,7 +27885,7 @@ function write_csv_stream(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
while(R <= r.e.r) {
++R;
if ((rowinfo[R-1]||{}).hidden) continue;
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, w, o);
if(row != null) {
if(row || (o.blankrows !== false)) return stream.push((w++ ? RS : "") + row);
}
@ -27885,10 +27982,165 @@ function write_json_stream(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return stream;
}
function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
var stream = _Readable();
var opts = o == null ? {} : o;
var stride = +opts.stride || 10;
if(!wb.SSF) wb.SSF = dup(table_fmt);
if(wb.SSF) {
make_ssf(); SSF_load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
}
/* do one pass to determine styles since they must be added before tables */
wb.SheetNames.forEach(function(n) {
var ws = wb.Sheets[n];
if(!ws || !ws["!ref"]) return;
var range = decode_range(ws["!ref"]);
var dense = ws["!data"] != null;
var ddata = dense ? ws["!data"] : [];
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
addr.r = R;
if(dense && !ddata[R]) continue;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var cell = dense ? ddata[R][C] : ws[encode_col(C) + encode_row(R)];
if(!cell) continue;
if(cell.t == "d" && cell.z == null) { cell = dup(cell); cell.z = table_fmt[14]; }
void get_cell_style(opts.cellXfs, cell, opts);
}
}
});
var sty = write_sty_xlml(wb, opts);
var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
stream._read = function() { switch(stage) {
/* header */
case 0: {
stage = 1;
stream.push(XML_HEADER);
stream.push("<Workbook" + wxt_helper({
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
'xmlns:x': XLMLNS.x,
'xmlns:ss': XLMLNS.ss,
'xmlns:dt': XLMLNS.dt,
'xmlns:html': XLMLNS.html
}) + ">");
} break;
/* preamble */
case 1: {
stage = 2;
stream.push(write_props_xlml(wb, opts));
stream.push(write_wb_xlml(wb, opts));
} break;
/* style and name tables */
case 2: {
stage = 3;
stream.push(sty);
stream.push(write_names_xlml(wb, opts));
} break;
/* worksheet preamble */
case 3: {
T = false;
if(wsidx >= wb.SheetNames.length) { stage = -1; stream.push(""); break; }
stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
ws = wb.Sheets[wb.SheetNames[wsidx]];
if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
var names = write_ws_xlml_names(ws, opts, wsidx, wb);
if(names.length) stream.push("<Names>" + names + "</Names>");
if(!ws["!ref"]) return (stage = 5);
range = safe_decode_range(ws["!ref"]);
R = range.s.r;
stage = 4;
} break;
/* worksheet intramble */
case 4: {
if(R < 0 || R > range.e.r) { if(T) stream.push("</Table>"); return void (stage = 5); }
if(R <= range.s.r) {
if(ws['!cols']) ws['!cols'].forEach(function(n, i) {
process_col(n);
var w = !!n.width;
var p = col_obj_w(i, n);
var k/*:any*/ = {"ss:Index":i+1};
if(w) k['ss:Width'] = width2px(p.width);
if(n.hidden) k['ss:Hidden']="1";
if(!T) { T = true; stream.push("<Table>"); }
stream.push(writextag("Column",null,k));
});
dense = ws["!data"] != null;
if(dense) darr = ws["!data"];
addr.r = addr.c = 0;
}
/* process `stride` rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < stride; ++R, ++cnt) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
if(!(dense && !darr[R])) for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
if(marr[mi].s.r > R) continue;
if(marr[mi].e.c < C) continue;
if(marr[mi].e.r < R) continue;
if(marr[mi].s.c != C || marr[mi].s.r != R) skip = true;
break;
}
if(skip) continue;
var ref = encode_col(C) + encode_row(R), cell = dense ? darr[R][C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, wsidx, wb, addr));
}
row.push("</Row>");
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
} break;
/* worksheet postamble */
case 5: {
stream.push(write_ws_xlml_wsopts(ws, opts, wsidx, wb));
if(ws && ws["!autofilter"]) stream.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
stream.push("</Worksheet>");
wsidx++; R = -1;
return void (stage = 3);
}
/* footer */
case -1: {
stage = -2;
stream.push("</Workbook>");
} break;
/* exeunt */
case -2: stream.push(null); break;
}};
return stream;
}
var __stream = {
to_json: write_json_stream,
to_html: write_html_stream,
to_csv: write_csv_stream,
to_xlml: write_xlml_stream,
set_readable: set_readable
};
if(typeof parse_xlscfb !== "undefined") XLSX.parse_xlscfb = parse_xlscfb;

375
xlsx.js generated

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
var $cptable;
@ -539,6 +539,7 @@ function SSF_large_exp(v) {
}
function SSF_general_num(v) {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1232,6 +1233,8 @@ function choose_fmt(f, v) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1268,6 +1271,8 @@ function SSF_format(fmt,v,o) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt, idx) {
@ -1391,7 +1396,6 @@ function SSF__load(fmt, idx) {
var CRC32 = (function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*global Int32Array */
function signed_crc_table() {
var c = 0, table = new Array(256);
@ -2790,8 +2794,8 @@ function parse_local_file(blob, csz, usz, o, EF) {
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2802,7 +2806,7 @@ function parse_local_file(blob, csz, usz, o, EF) {
var data = blob.slice(blob.l, blob.l + _csz);
switch(meth) {
case 8: data = _inflateRawSync(blob, _usz); break;
case 0: break; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2837,9 +2841,10 @@ function write_zip(cfb, options) {
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3732,6 +3737,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3802,6 +3810,26 @@ function parsexmltag(tag, skip_root, skip_LC) {
}
return z;
}
function parsexmltagraw(tag, skip_root, skip_LC) {
var z = ({});
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x) { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4308,7 +4336,8 @@ function recordhopper(data, cb, opts) {
/* control buffer usage for fixed-length buffers */
function buf_array() {
var bufs = [], blksz = has_buf ? 256 : 2048;
var bufs = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz) {
var o = (new_buf(sz));
prep_blob(o, 0);
@ -4337,10 +4366,15 @@ function buf_array() {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs });
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 });
}
function write_record(ba, type, payload, length) {
@ -4527,7 +4561,7 @@ function sheet_add_aoa(_ws, data, opts) {
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws = _ws || ({});
var ws = _ws || (dense ? ({"!data": []}) : ({}));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4552,31 +4586,35 @@ function sheet_add_aoa(_ws, data, opts) {
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell = ({v: data[R][C] });
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell = ({v: data_R[C], t:"" });
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4590,7 +4628,7 @@ function sheet_add_aoa(_ws, data, opts) {
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr;
var cell_ref = encode_col(__C) + (__R + 1);
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4600,7 +4638,6 @@ function sheet_add_aoa(_ws, data, opts) {
return ws;
}
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
function parse_Int32LE(data) {
return data.read_shift(4, 'i');
}
@ -6182,8 +6219,8 @@ function parse_TypedPropertyValue(blob, type, _opts) {
case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
case 0x1E /*VT_LPSTR*/: return parse_lpstr(blob, t, 4).replace(chr0,'');
case 0x1F /*VT_LPWSTR*/: return parse_lpwstr(blob);
case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@ -8475,7 +8512,7 @@ var SYLK = (function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -8704,7 +8741,7 @@ var ETH = (function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -8747,11 +8784,7 @@ var ETH = (function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -8761,6 +8794,19 @@ var ETH = (function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -8792,6 +8838,7 @@ var PRN = (function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -8909,6 +8956,8 @@ var PRN = (function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -9608,7 +9657,6 @@ var WK_ = (function() {
else console.error("WK1 bad formula parse |" + out.join("|") + "|");
}
function parse_cell_3(blob) {
var o = [{c:0,r:0}, {t:'n',v:0}, 0];
o[0].r = blob.read_shift(2); o[3] = blob[blob.l++]; o[0].c = blob[blob.l++];
@ -10843,6 +10891,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;
@ -11235,6 +11287,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -15764,7 +15817,7 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
var merges = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -16223,16 +16276,17 @@ return function parse_ws_xml_data(sdata, s, opts, guess, themes, styles, wb) {
function write_ws_xml_data(ws, opts, idx, wb) {
var o = [], r = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}), row, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -17233,12 +17287,15 @@ function write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904) {
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) {
if(last_seen) write_record(ba, 0x000D /* BrtShortRk */, write_BrtShortRk(cell, o));
else write_record(ba, 0x0002 /* BrtCellRk */, write_BrtCellRk(cell, o));
} else if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else if(!isFinite(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
o.t = "e";
if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
}
} else {
if(last_seen) write_record(ba, 0x0010 /* BrtShortReal */, write_BrtShortReal(cell, o));
else write_record(ba, 0x0005 /* BrtCellReal */, write_BrtCellReal(cell, o));
@ -17260,23 +17317,24 @@ function write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904) {
}
function write_CELLTABLE(ba, ws, idx, opts, wb) {
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols = [];
var range = safe_decode_range(ws['!ref'] || "A1"), rr = "", cols = [];
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
write_record(ba, 0x0091 /* BrtBeginSheetData */);
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, row = dense ? ws["!data"][range.s.r] : [];
var cap = range.e.r;
if(ws['!rows']) cap = Math.max(range.e.r, ws['!rows'].length - 1);
for(var R = range.s.r; R <= cap; ++R) {
rr = encode_row(R);
if(dense) row = ws["!data"][R];
/* [ACCELLTABLE] */
/* BrtRowHdr */
write_row_header(ba, ws, range, R);
if(dense && !row) continue;
var last_seen = false;
if(R <= range.e.r) for(var C = range.s.c; C <= range.e.c; ++C) {
/* *16384CELL */
if(R === range.s.r) cols[C] = encode_col(C);
ref = cols[C] + rr;
var cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) { last_seen = false; continue; }
/* write cell */
last_seen = write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904);
@ -19539,7 +19597,13 @@ function write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr){
var t = "", p = "";
switch(cell.t) {
case 'z': if(!opts.sheetStubs) return ""; break;
case 'n': t = 'Number'; p = String(cell.v); break;
case 'n': {
if(!isFinite(cell.v)) {
t = 'Error'; p = BErr[isNaN(cell.v) ? 0x24 : 0x07];
} else {
t = 'Number'; p = String(cell.v);
}
} break;
case 'b': t = 'Boolean'; p = (cell.v ? "1" : "0"); break;
case 'e': t = 'Error'; p = BErr[cell.v]; break;
case 'd': t = 'DateTime'; p = new Date(cell.v).toISOString(); if(cell.z == null) cell.z = cell.z || table_fmt[14]; break;
@ -19581,9 +19645,12 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
o.push(writextag("Column",null,k));
});
var dense = ws["!data"] != null;
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
@ -19594,7 +19661,6 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
break;
}
if(skip) continue;
var addr = {r:R,c:C};
var ref = encode_col(C) + encode_row(R), cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr));
}
@ -19618,7 +19684,7 @@ function write_ws_xlml(idx, opts, wb) {
/* WorksheetOptions */
o.push(write_ws_xlml_wsopts(ws, opts, idx, wb));
if(ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
if(ws && ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
return o.join("");
}
@ -19637,11 +19703,10 @@ function write_xlml(wb, opts) {
d.push(write_props_xlml(wb, opts));
d.push(write_wb_xlml(wb, opts));
d.push("");
d.push("");
d.push(write_names_xlml(wb, opts));
for(var i = 0; i < wb.SheetNames.length; ++i)
d.push(writextag("Worksheet", write_ws_xlml(i, opts, wb), {"ss:Name":escapexml(wb.SheetNames[i])}));
d[2] = write_sty_xlml(wb, opts);
d[3] = write_names_xlml(wb, opts);
return XML_HEADER + writextag("Workbook", d.join(""), {
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
@ -21822,7 +21887,7 @@ function write_ws_biff2(ba, ws, idx, opts, wb) {
if(range.e.c > 0xFF || range.e.r > 0x3FFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, 0x3FFF);
range.e.r = Math.min(range.e.r, 0x3FFF);
}
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
var row = [], comments = [];
@ -22231,9 +22296,9 @@ function write_ws_biff8(idx, opts, wb) {
var range = safe_decode_range(ws['!ref'] || "A1");
var MAX_ROWS = b8 ? 65536 : 16384;
if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV" + MAX_ROWS);
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, MAX_ROWS-1);
range.e.r = Math.min(range.e.r, MAX_ROWS-1);
}
write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
@ -22268,12 +22333,11 @@ function write_ws_biff8(idx, opts, wb) {
if(dense) row = ws["!data"][R] || [];
rr = encode_row(R);
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var cell = dense ? row[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) continue;
/* write cell */
write_ws_biff8_cell(ba, cell, R, C, opts, date1904);
if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
if(b8 && cell.l) ws['!links'].push([cols[C] + rr, cell.l]);
if(cell.c) comments.push([cell.c, R, C]);
}
}
@ -22417,6 +22481,9 @@ function write_biff_buf(wb, opts) {
if(range.e.c > 255) { // note: 255 is IV
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
if(range.e.r > 65535) {
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond row 65536. Data may be lost.");
}
}
var o = opts || {};
@ -22476,6 +22543,8 @@ function html_to_sheet(str, _opts) {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -22503,6 +22572,10 @@ function make_html_row(ws, r, R, o) {
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({});
@ -22613,6 +22686,7 @@ function sheet_add_dom(ws, table, _opts) {
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -22621,7 +22695,7 @@ function sheet_add_dom(ws, table, _opts) {
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -22922,7 +22996,7 @@ function parse_content_xml(d, _opts, _nfm) {
var Sheets = {}, SheetNames = [];
var ws = ({}); if(opts.dense) ws["!data"] = [];
var Rn, q;
var ctag = ({value:""});
var ctag = ({value:""}), ctag2 = ({});
var textp = "", textpidx = 0, textptag, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -23016,6 +23090,7 @@ function parse_content_xml(d, _opts, _nfm) {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({});
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null});
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -23069,6 +23144,9 @@ function parse_content_xml(d, _opts, _nfm) {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -23732,9 +23810,22 @@ var write_content_ods = /* @__PURE__ */(function() {
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -26971,6 +27062,8 @@ function readSync(data, opts) {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -27326,7 +27419,7 @@ function sheet_to_json(sheet, opts) {
}
var qreg = /"/g;
function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
function make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o) {
var isempty = true;
var row = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -27339,7 +27432,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -27366,7 +27459,7 @@ function sheet_to_csv(sheet, opts) {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -27381,7 +27474,7 @@ function sheet_to_txt(sheet, opts) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet) {
function sheet_to_formulae(sheet, opts) {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols = [], C;
@ -27402,6 +27495,7 @@ function sheet_to_formulae(sheet) {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";
@ -27670,7 +27764,7 @@ function write_csv_stream(sheet, opts) {
while(R <= r.e.r) {
++R;
if ((rowinfo[R-1]||{}).hidden) continue;
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, w, o);
if(row != null) {
if(row || (o.blankrows !== false)) return stream.push((w++ ? RS : "") + row);
}
@ -27767,10 +27861,165 @@ function write_json_stream(sheet, opts) {
return stream;
}
function write_xlml_stream(wb, o) {
var stream = _Readable();
var opts = o == null ? {} : o;
var stride = +opts.stride || 10;
if(!wb.SSF) wb.SSF = dup(table_fmt);
if(wb.SSF) {
make_ssf(); SSF_load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
}
/* do one pass to determine styles since they must be added before tables */
wb.SheetNames.forEach(function(n) {
var ws = wb.Sheets[n];
if(!ws || !ws["!ref"]) return;
var range = decode_range(ws["!ref"]);
var dense = ws["!data"] != null;
var ddata = dense ? ws["!data"] : [];
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
addr.r = R;
if(dense && !ddata[R]) continue;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var cell = dense ? ddata[R][C] : ws[encode_col(C) + encode_row(R)];
if(!cell) continue;
if(cell.t == "d" && cell.z == null) { cell = dup(cell); cell.z = table_fmt[14]; }
void get_cell_style(opts.cellXfs, cell, opts);
}
}
});
var sty = write_sty_xlml(wb, opts);
var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
stream._read = function() { switch(stage) {
/* header */
case 0: {
stage = 1;
stream.push(XML_HEADER);
stream.push("<Workbook" + wxt_helper({
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
'xmlns:x': XLMLNS.x,
'xmlns:ss': XLMLNS.ss,
'xmlns:dt': XLMLNS.dt,
'xmlns:html': XLMLNS.html
}) + ">");
} break;
/* preamble */
case 1: {
stage = 2;
stream.push(write_props_xlml(wb, opts));
stream.push(write_wb_xlml(wb, opts));
} break;
/* style and name tables */
case 2: {
stage = 3;
stream.push(sty);
stream.push(write_names_xlml(wb, opts));
} break;
/* worksheet preamble */
case 3: {
T = false;
if(wsidx >= wb.SheetNames.length) { stage = -1; stream.push(""); break; }
stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
ws = wb.Sheets[wb.SheetNames[wsidx]];
if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
var names = write_ws_xlml_names(ws, opts, wsidx, wb);
if(names.length) stream.push("<Names>" + names + "</Names>");
if(!ws["!ref"]) return (stage = 5);
range = safe_decode_range(ws["!ref"]);
R = range.s.r;
stage = 4;
} break;
/* worksheet intramble */
case 4: {
if(R < 0 || R > range.e.r) { if(T) stream.push("</Table>"); return void (stage = 5); }
if(R <= range.s.r) {
if(ws['!cols']) ws['!cols'].forEach(function(n, i) {
process_col(n);
var w = !!n.width;
var p = col_obj_w(i, n);
var k = {"ss:Index":i+1};
if(w) k['ss:Width'] = width2px(p.width);
if(n.hidden) k['ss:Hidden']="1";
if(!T) { T = true; stream.push("<Table>"); }
stream.push(writextag("Column",null,k));
});
dense = ws["!data"] != null;
if(dense) darr = ws["!data"];
addr.r = addr.c = 0;
}
/* process `stride` rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < stride; ++R, ++cnt) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
if(!(dense && !darr[R])) for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
if(marr[mi].s.r > R) continue;
if(marr[mi].e.c < C) continue;
if(marr[mi].e.r < R) continue;
if(marr[mi].s.c != C || marr[mi].s.r != R) skip = true;
break;
}
if(skip) continue;
var ref = encode_col(C) + encode_row(R), cell = dense ? darr[R][C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, wsidx, wb, addr));
}
row.push("</Row>");
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
} break;
/* worksheet postamble */
case 5: {
stream.push(write_ws_xlml_wsopts(ws, opts, wsidx, wb));
if(ws && ws["!autofilter"]) stream.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
stream.push("</Worksheet>");
wsidx++; R = -1;
return void (stage = 3);
}
/* footer */
case -1: {
stage = -2;
stream.push("</Workbook>");
} break;
/* exeunt */
case -2: stream.push(null); break;
}};
return stream;
}
var __stream = {
to_json: write_json_stream,
to_html: write_html_stream,
to_csv: write_csv_stream,
to_xlml: write_xlml_stream,
set_readable: set_readable
};
if(typeof parse_xlscfb !== "undefined") XLSX.parse_xlscfb = parse_xlscfb;

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -559,6 +559,7 @@ function SSF_large_exp(v/*:number*/)/*:string*/ {
}
function SSF_general_num(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1256,6 +1257,8 @@ function choose_fmt(f/*:string*/, v/*:any*/) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1292,6 +1295,8 @@ function SSF_format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt/*:string*/, idx/*:?number*/)/*:number*/ {
@ -1451,7 +1456,9 @@ type CFBFiles = {[n:string]:CFBEntry};
var CRC32 = /*#__PURE__*/(function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*::
type CRC32TableType = Array<number> | Int32Array;
*/
/*global Int32Array */
function signed_crc_table()/*:any*/ {
var c = 0, table/*:Array<number>*/ = new Array(256);
@ -1489,7 +1496,7 @@ 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*/ {
function crc32_bstr(bstr/*:string*/, seed/*:?number*/)/*:number*/ {
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;
@ -2855,8 +2862,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2867,7 +2874,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; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2902,9 +2909,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3803,6 +3811,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3873,6 +3884,26 @@ function parsexmltag(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*
}
return z;
}
function parsexmltagraw(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*/)/*:any*/ {
var z = ({}/*:any*/);
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x/*:string*/)/*:string*/ { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4385,7 +4416,8 @@ function recordhopper(data, cb/*:RecordHopperCB*/, opts/*:?any*/) {
/* control buffer usage for fixed-length buffers */
function buf_array()/*:BufArray*/ {
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 256 : 2048;
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz/*:number*/)/*:Block*/ {
var o/*:Block*/ = (new_buf(sz)/*:any*/);
prep_blob(o, 0);
@ -4414,10 +4446,15 @@ function buf_array()/*:BufArray*/ {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs }/*:any*/);
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 }/*:any*/);
}
function write_record(ba/*:BufArray*/, type/*:number*/, payload, length/*:?number*/) {
@ -4605,7 +4642,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
var ws/*:Worksheet*/ = _ws || (dense ? ({"!data": []}) : ({}/*:any*/));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4630,31 +4667,35 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data_R[C], t:"" }/*:any*/);
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; /*# DIV/0 */ }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4668,7 +4709,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr/*:any*/;
var cell_ref = encode_col(__C) + (__R + 1)/*:any*/;
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4678,7 +4719,6 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
return ws;
}
function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_add_aoa(null, data, opts); }
/* [MS-OLEPS] 2.2 PropertyType */
// Note: some tree shakers cannot handle VT_VECTOR | $CONST, hence extra vars
//var VT_EMPTY = 0x0000;
@ -6329,7 +6369,7 @@ var SYLK = /*#__PURE__*/(function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -6558,7 +6598,7 @@ var ETH = /*#__PURE__*/(function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -6601,11 +6641,7 @@ var ETH = /*#__PURE__*/(function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -6615,6 +6651,19 @@ var ETH = /*#__PURE__*/(function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -6646,6 +6695,7 @@ var PRN = /*#__PURE__*/(function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -6763,6 +6813,8 @@ var PRN = /*#__PURE__*/(function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -7440,6 +7492,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -8710,7 +8763,7 @@ function parse_ws_xml(data/*:?string*/, opts, idx/*:number*/, rels, wb/*:WBWBPro
var merges/*:Array<Range>*/ = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -9169,16 +9222,17 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th
function write_ws_xml_data(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbook*//*::, rels*/)/*:string*/ {
var o/*:Array<string>*/ = [], r/*:Array<string>*/ = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols/*:Array<string>*/ = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}/*:any*/), row/*:RowInfo*/, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -9916,6 +9970,8 @@ function html_to_sheet(str/*:string*/, _opts)/*:Workbook*/ {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -9943,6 +9999,10 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({}/*:any*/);
@ -10053,6 +10113,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -10061,7 +10122,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -10362,7 +10423,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
var Sheets = {}, SheetNames/*:Array<string>*/ = [];
var ws = ({}/*:any*/); if(opts.dense) ws["!data"] = [];
var Rn, q/*:: :any = ({t:"", v:null, z:null, w:"",c:[],}:any)*/;
var ctag = ({value:""}/*:any*/);
var ctag = ({value:""}/*:any*/), ctag2 = ({}/*:any*/);
var textp = "", textpidx = 0, textptag/*:: = {}*/, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -10456,6 +10517,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({}/*:any*/);
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null/*:: , z:null, w:"",c:[]*/}/*:any*/);
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -10509,6 +10571,9 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -11172,9 +11237,22 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = /* @__PURE__ */(function
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -12151,6 +12229,8 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -12513,7 +12593,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) {
}
var qreg = /"/g;
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, w/*:number*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
var isempty = true;
var row/*:Array<string>*/ = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -12526,7 +12606,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -12553,7 +12633,7 @@ function sheet_to_csv(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/)/*:string*/ {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -12568,7 +12648,7 @@ function sheet_to_txt(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
function sheet_to_formulae(sheet/*:Worksheet*/, opts/*:?Sheet2FormulaOpts*/)/*:Array<string>*/ {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols/*:Array<string>*/ = [], C;
@ -12589,6 +12669,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
var $cptable;
@ -539,6 +539,7 @@ function SSF_large_exp(v) {
}
function SSF_general_num(v) {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1232,6 +1233,8 @@ function choose_fmt(f, v) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1268,6 +1271,8 @@ function SSF_format(fmt,v,o) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt, idx) {
@ -1391,7 +1396,6 @@ function SSF__load(fmt, idx) {
var CRC32 = (function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*global Int32Array */
function signed_crc_table() {
var c = 0, table = new Array(256);
@ -2790,8 +2794,8 @@ function parse_local_file(blob, csz, usz, o, EF) {
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2802,7 +2806,7 @@ function parse_local_file(blob, csz, usz, o, EF) {
var data = blob.slice(blob.l, blob.l + _csz);
switch(meth) {
case 8: data = _inflateRawSync(blob, _usz); break;
case 0: break; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2837,9 +2841,10 @@ function write_zip(cfb, options) {
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3732,6 +3737,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3802,6 +3810,26 @@ function parsexmltag(tag, skip_root, skip_LC) {
}
return z;
}
function parsexmltagraw(tag, skip_root, skip_LC) {
var z = ({});
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x) { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4308,7 +4336,8 @@ function recordhopper(data, cb, opts) {
/* control buffer usage for fixed-length buffers */
function buf_array() {
var bufs = [], blksz = has_buf ? 256 : 2048;
var bufs = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz) {
var o = (new_buf(sz));
prep_blob(o, 0);
@ -4337,10 +4366,15 @@ function buf_array() {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs });
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 });
}
function write_record(ba, type, payload, length) {
@ -4523,7 +4557,7 @@ function sheet_add_aoa(_ws, data, opts) {
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws = _ws || ({});
var ws = _ws || (dense ? ({"!data": []}) : ({}));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4548,31 +4582,35 @@ function sheet_add_aoa(_ws, data, opts) {
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell = ({v: data[R][C] });
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell = ({v: data_R[C], t:"" });
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4586,7 +4624,7 @@ function sheet_add_aoa(_ws, data, opts) {
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr;
var cell_ref = encode_col(__C) + (__R + 1);
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4596,7 +4634,6 @@ function sheet_add_aoa(_ws, data, opts) {
return ws;
}
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
/* [MS-OLEPS] 2.2 PropertyType */
// Note: some tree shakers cannot handle VT_VECTOR | $CONST, hence extra vars
//var VT_EMPTY = 0x0000;
@ -6246,7 +6283,7 @@ var SYLK = (function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -6475,7 +6512,7 @@ var ETH = (function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -6518,11 +6555,7 @@ var ETH = (function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -6532,6 +6565,19 @@ var ETH = (function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -6563,6 +6609,7 @@ var PRN = (function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -6680,6 +6727,8 @@ var PRN = (function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -7357,6 +7406,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -8627,7 +8677,7 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
var merges = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -9086,16 +9136,17 @@ return function parse_ws_xml_data(sdata, s, opts, guess, themes, styles, wb) {
function write_ws_xml_data(ws, opts, idx, wb) {
var o = [], r = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}), row, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -9831,6 +9882,8 @@ function html_to_sheet(str, _opts) {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -9858,6 +9911,10 @@ function make_html_row(ws, r, R, o) {
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({});
@ -9968,6 +10025,7 @@ function sheet_add_dom(ws, table, _opts) {
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -9976,7 +10034,7 @@ function sheet_add_dom(ws, table, _opts) {
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)});
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -10277,7 +10335,7 @@ function parse_content_xml(d, _opts, _nfm) {
var Sheets = {}, SheetNames = [];
var ws = ({}); if(opts.dense) ws["!data"] = [];
var Rn, q;
var ctag = ({value:""});
var ctag = ({value:""}), ctag2 = ({});
var textp = "", textpidx = 0, textptag, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -10371,6 +10429,7 @@ function parse_content_xml(d, _opts, _nfm) {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({});
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null});
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -10424,6 +10483,9 @@ function parse_content_xml(d, _opts, _nfm) {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -11087,9 +11149,22 @@ var write_content_ods = /* @__PURE__ */(function() {
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -12062,6 +12137,8 @@ function readSync(data, opts) {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -12417,7 +12494,7 @@ function sheet_to_json(sheet, opts) {
}
var qreg = /"/g;
function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
function make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o) {
var isempty = true;
var row = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -12430,7 +12507,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -12457,7 +12534,7 @@ function sheet_to_csv(sheet, opts) {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -12472,7 +12549,7 @@ function sheet_to_txt(sheet, opts) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet) {
function sheet_to_formulae(sheet, opts) {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols = [], C;
@ -12493,6 +12570,7 @@ function sheet_to_formulae(sheet) {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";

380
xlsx.mjs generated

@ -3,7 +3,7 @@
/*exported XLSX */
/*global process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false */
var XLSX = {};
XLSX.version = '0.20.2';
XLSX.version = '0.20.2strm';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -558,6 +558,7 @@ function SSF_large_exp(v/*:number*/)/*:string*/ {
}
function SSF_general_num(v/*:number*/)/*:string*/ {
if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!";
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
@ -1255,6 +1256,8 @@ function choose_fmt(f/*:string*/, v/*:any*/) {
if(l<4 && lat>-1) --l;
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
/* NOTE: most spreadsheet software do not support NaN or infinities */
if(typeof v === "number" && !isFinite(v)) v = 0;
switch(fmt.length) {
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
@ -1291,6 +1294,8 @@ function SSF_format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) {
if(SSF_isgeneral(f[1])) return SSF_general(v, o);
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
else if(v === "" || v == null) return "";
else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!";
else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!";
return eval_fmt(f[1], v, o, f[0]);
}
function SSF_load(fmt/*:string*/, idx/*:?number*/)/*:number*/ {
@ -1450,7 +1455,9 @@ type CFBFiles = {[n:string]:CFBEntry};
var CRC32 = /*#__PURE__*/(function() {
var CRC32 = {};
CRC32.version = '1.2.0';
/* see perf/crc32table.js */
/*::
type CRC32TableType = Array<number> | Int32Array;
*/
/*global Int32Array */
function signed_crc_table()/*:any*/ {
var c = 0, table/*:Array<number>*/ = new Array(256);
@ -1488,7 +1495,7 @@ 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*/ {
function crc32_bstr(bstr/*:string*/, seed/*:?number*/)/*:number*/ {
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;
@ -2854,8 +2861,8 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if(EF) {
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
if((EF[0x0001]||{}).usz) _usz = EF[0x0001].usz;
if((EF[0x0001]||{}).csz) _csz = EF[0x0001].csz;
}
}
blob.l += efsz;
@ -2866,7 +2873,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; // TODO: scan for magic number
case 0: blob.l += _csz; break; // TODO: scan for magic number
default: throw new Error("Unsupported ZIP Compression method " + meth);
}
@ -2901,9 +2908,10 @@ function write_zip(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/
for(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;
if(!fi.size || !fi.content || (Array.isArray(fi.content) && fi.content.length == 0) || fp == "\u0001Sh33tJ5") continue;
var start = start_cd;
/* TODO: CP437 filename */
var namebuf = new_buf(fp.length);
for(j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 0x7F);
@ -3802,6 +3810,9 @@ function zipentries(zip) {
function zip_add_file(zip, path, content) {
if(zip.FullPaths) {
if(Array.isArray(content) && typeof content[0] == "string") {
content = content.join("");
}
if(typeof content == "string") {
var res;
if(has_buf) res = Buffer_from(content);
@ -3872,6 +3883,26 @@ function parsexmltag(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*
}
return z;
}
function parsexmltagraw(tag/*:string*/, skip_root/*:?boolean*/, skip_LC/*:?boolean*/)/*:any*/ {
var z = ({}/*:any*/);
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i].slice(1);
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.slice(c+1+quot, cc.length-quot);
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
if(!skip_LC) z[q.toLowerCase()] = v;
}
return z;
}
function strip_ns(x/*:string*/)/*:string*/ { return x.replace(nsregex2, "<$1"); }
var encodings = {
@ -4384,7 +4415,8 @@ function recordhopper(data, cb/*:RecordHopperCB*/, opts/*:?any*/) {
/* control buffer usage for fixed-length buffers */
function buf_array()/*:BufArray*/ {
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 256 : 2048;
var bufs/*:Array<Block>*/ = [], blksz = has_buf ? 16384 : 2048;
var has_buf_copy = has_buf && (typeof new_buf(blksz).copy == "function");
var newblk = function ba_newblk(sz/*:number*/)/*:Block*/ {
var o/*:Block*/ = (new_buf(sz)/*:any*/);
prep_blob(o, 0);
@ -4413,10 +4445,15 @@ function buf_array()/*:BufArray*/ {
endbuf();
return bconcat(bufs);
};
var end2 = function() {
endbuf(); return bufs;
};
var push = function ba_push(buf) { endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz); };
var push = function ba_push(buf) {
endbuf(); curbuf = buf; if(curbuf.l == null) curbuf.l = curbuf.length; next(blksz);
};
return ({ next:next, push:push, end:end, _bufs:bufs }/*:any*/);
return ({ next:next, push:push, end:end, _bufs:bufs, end2:end2 }/*:any*/);
}
function write_record(ba/*:BufArray*/, type/*:number*/, payload, length/*:?number*/) {
@ -4604,7 +4641,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var o = opts || {};
var dense = _ws ? (_ws["!data"] != null) : o.dense;
if(DENSE != null && dense == null) dense = DENSE;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
var ws/*:Worksheet*/ = _ws || (dense ? ({"!data": []}) : ({}/*:any*/));
if(dense && !ws["!data"]) ws["!data"] = [];
var _R = 0, _C = 0;
if(ws && o.origin != null) {
@ -4629,31 +4666,35 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
for(var R = 0; R != data.length; ++R) {
if(!data[R]) continue;
if(!Array.isArray(data[R])) throw new Error("aoa_to_sheet expects an array of arrays");
var __R = _R + R, __Rstr = "" + (__R + 1);
//console.log("!!", R, _R, __R);
var __R = _R + R;
if(dense) {
if(!ws["!data"][__R]) ws["!data"][__R] = [];
row = ws["!data"][__R];
}
for(var C = 0; C != data[R].length; ++C) {
if(typeof data[R][C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
var data_R = data[R];
for(var C = 0; C != data_R.length; ++C) {
if(typeof data_R[C] === 'undefined') continue;
var cell/*:Cell*/ = ({v: data_R[C], t:"" }/*:any*/);
var __C = _C + C;
if(range.s.r > __R) range.s.r = __R;
if(range.s.c > __C) range.s.c = __C;
if(range.e.r < __R) range.e.r = __R;
if(range.e.c < __C) range.e.c = __C;
seen = true;
if(data[R][C] && typeof data[R][C] === 'object' && !Array.isArray(data[R][C]) && !(data[R][C] instanceof Date)) cell = data[R][C];
if(data_R[C] && typeof data_R[C] === 'object' && !Array.isArray(data_R[C]) && !(data_R[C] instanceof Date)) cell = data_R[C];
else {
if(Array.isArray(cell.v)) { cell.f = data[R][C][1]; cell.v = cell.v[0]; }
if(Array.isArray(cell.v)) { cell.f = data_R[C][1]; cell.v = cell.v[0]; }
if(cell.v === null) {
if(cell.f) cell.t = 'n';
else if(o.nullError) { cell.t = 'e'; cell.v = 0; }
else if(!o.sheetStubs) continue;
else cell.t = 'z';
}
else if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'number') {
if(isFinite(cell.v)) cell.t = 'n';
else if(isNaN(cell.v)) { cell.t = 'e'; cell.v = 0x0F; /* #VALUE! */ }
else { cell.t = 'e'; cell.v = 0x07; /*# DIV/0 */ }
}
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.z = o.dateNF || table_fmt[14];
@ -4667,7 +4708,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
if(row[__C] && row[__C].z) cell.z = row[__C].z;
row[__C] = cell;
} else {
var cell_ref = encode_col(__C) + __Rstr/*:any*/;
var cell_ref = encode_col(__C) + (__R + 1)/*:any*/;
if(ws[cell_ref] && ws[cell_ref].z) cell.z = ws[cell_ref].z;
ws[cell_ref] = cell;
}
@ -4677,7 +4718,6 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
return ws;
}
function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_add_aoa(null, data, opts); }
function parse_Int32LE(data) {
return data.read_shift(4, 'i');
}
@ -6261,8 +6301,8 @@ function parse_TypedPropertyValue(blob, type/*:number*/, _opts)/*:any*/ {
case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
case 0x1E /*VT_LPSTR*/: return parse_lpstr(blob, t, 4).replace(chr0,'');
case 0x1F /*VT_LPWSTR*/: return parse_lpwstr(blob);
case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@ -8557,7 +8597,7 @@ var SYLK = /*#__PURE__*/(function() {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
switch(cell.t) {
case 'n':
o += (cell.v||0);
o += isFinite(cell.v) ? (cell.v||0) : BErr[isNaN(cell.v) ? 0x24 : 0x07];
if(cell.f && !cell.F) o += ";E" + a1_to_rc(cell.f, {r:R, c:C}); break;
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
case 'e': o += cell.w || BErr[cell.v] || cell.v; break;
@ -8786,7 +8826,7 @@ var ETH = /*#__PURE__*/(function() {
case 'vtc':
switch(record[3]) {
case 'nl': arr[R][C] = +record[4] ? true : false; break;
default: arr[R][C] = +record[4]; break;
default: arr[R][C] = record[record.length-1].charAt(0) == "#" ? ({t: "e", v: RBErr[record[record.length-1]] }) : +record[4]; break;
}
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
@ -8829,11 +8869,7 @@ var ETH = /*#__PURE__*/(function() {
if(!cell || cell.v == null || cell.t === 'z') continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(encode(cell.v)); break;
case 'n':
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
break;
case 's': oo.push(encode(cell.v)); break;
case 'b':
oo[2] = 'vt'+(cell.f?'f':'c'); oo[3]='nl'; oo[4]=cell.v?"1":"0";
oo[5] = encode(cell.f||(cell.v?'TRUE':'FALSE'));
@ -8843,6 +8879,19 @@ var ETH = /*#__PURE__*/(function() {
oo[2] = 'vtc'; oo[3] = 'nd'; oo[4] = ""+t;
oo[5] = cell.w || SSF_format(cell.z || table_fmt[14], t);
break;
case 'n':
if(isFinite(cell.v)) {
if(!cell.f) { oo[2]='v'; oo[3]=cell.v; }
else { oo[2]='vtf'; oo[3]='n'; oo[4]=cell.v; oo[5]=encode(cell.f); }
} else {
oo[2] = 'vt' + (cell.f ? 'f' : 'c');
oo[3] = "e" + BErr[isNaN(cell.v) ? 0x24 : 0x07];
oo[4] = "0";
oo[5] = cell.f || oo[3].slice(1);
oo[6] = "e";
oo[7] = oo[3].slice(1);
}
break;
case 'e': continue;
}
o.push(oo.join(":"));
@ -8874,6 +8923,7 @@ var PRN = /*#__PURE__*/(function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(!isNaN(fuzzynum(data))) arr[R][C] = fuzzynum(data);
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else if(data.charCodeAt(0) == 35 /* # */ && RBErr[data] != null) arr[R][C] = ({ t: 'e', v: RBErr[data], w: data });
else arr[R][C] = data;
}
@ -8991,6 +9041,8 @@ var PRN = /*#__PURE__*/(function() {
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(!o.cellNF) delete cell.z;
} else if(s.charCodeAt(0) == 35 /* # */ && RBErr[s] != null) {
cell.t = 'e'; cell.w = s; cell.v = RBErr[s];
} else {
cell.t = 's';
cell.v = s;
@ -9690,7 +9742,6 @@ var WK_ = /*#__PURE__*/(function() {
else console.error("WK1 bad formula parse |" + out.join("|") + "|");
}
function parse_cell_3(blob/*::, length*/) {
var o = [{c:0,r:0}, {t:'n',v:0}, 0];
o[0].r = blob.read_shift(2); o[3] = blob[blob.l++]; o[0].c = blob[blob.l++];
@ -10926,6 +10977,10 @@ function rtf_to_sheet_str(str, opts) {
if (o.cellText !== false)
cell.w = cell.v;
cell.v = fuzzynum(cell.v);
} else if (RBErr[cell.v] != null) {
cell.t = "e";
cell.w = cell.v;
cell.v = RBErr[cell.v];
}
if (dense)
row[C] = cell;
@ -11318,6 +11373,7 @@ function parse_fonts(t, styles, themes, opts) {
if(y.val == '1') break;
y.codepage = CS2CP[parseInt(y.val, 10)];
break;
case '<charset/>': case '</charset>': break;
/* 18.?.? color CT_Color */
case '<color':
@ -15850,7 +15906,7 @@ function parse_ws_xml(data/*:?string*/, opts, idx/*:number*/, rels, wb/*:WBWBPro
var merges/*:Array<Range>*/ = [];
var _merge = data2.match(mergecregex);
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("=")+2));
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
var hlink = data2.match(hlinkregex);
@ -16309,16 +16365,17 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th
function write_ws_xml_data(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbook*//*::, rels*/)/*:string*/ {
var o/*:Array<string>*/ = [], r/*:Array<string>*/ = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols/*:Array<string>*/ = [], R=0, C=0, rows = ws['!rows'];
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, data = dense ? ws["!data"] : [];
var params = ({r:rr}/*:any*/), row/*:RowInfo*/, height = -1;
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
for(R = range.s.r; R <= range.e.r; ++R) {
r = [];
rr = encode_row(R);
var data_R = dense ? data[R] : [];
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
var _cell = dense ? data_R[C] : ws[ref];
if(_cell === undefined) continue;
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb, date1904)) != null) r.push(cell);
}
@ -17320,12 +17377,15 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) {
if(last_seen) write_record(ba, 0x000D /* BrtShortRk */, write_BrtShortRk(cell, o));
else write_record(ba, 0x0002 /* BrtCellRk */, write_BrtCellRk(cell, o));
} else if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else if(!isFinite(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
o.t = "e";
if(isNaN(cell.v)) {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x24}, o)); // #NUM!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x24}, o)); // #NUM!
} else {
if(last_seen) write_record(ba, 0x000E /* BrtShortError */, write_BrtShortError({t:"e", v: 0x07}, o)); // #DIV/0!
else write_record(ba, 0x0003 /* BrtCellError */, write_BrtCellError({t:"e", v: 0x07}, o)); // #DIV/0!
}
} else {
if(last_seen) write_record(ba, 0x0010 /* BrtShortReal */, write_BrtShortReal(cell, o));
else write_record(ba, 0x0005 /* BrtCellReal */, write_BrtCellReal(cell, o));
@ -17347,23 +17407,24 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
}
function write_CELLTABLE(ba, ws/*:Worksheet*/, idx/*:number*/, opts, wb/*:Workbook*/) {
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols/*:Array<string>*/ = [];
var range = safe_decode_range(ws['!ref'] || "A1"), rr = "", cols/*:Array<string>*/ = [];
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
write_record(ba, 0x0091 /* BrtBeginSheetData */);
var dense = ws["!data"] != null;
var dense = ws["!data"] != null, row = dense ? ws["!data"][range.s.r] : [];
var cap = range.e.r;
if(ws['!rows']) cap = Math.max(range.e.r, ws['!rows'].length - 1);
for(var R = range.s.r; R <= cap; ++R) {
rr = encode_row(R);
if(dense) row = ws["!data"][R];
/* [ACCELLTABLE] */
/* BrtRowHdr */
write_row_header(ba, ws, range, R);
if(dense && !row) continue;
var last_seen = false;
if(R <= range.e.r) for(var C = range.s.c; C <= range.e.c; ++C) {
/* *16384CELL */
if(R === range.s.r) cols[C] = encode_col(C);
ref = cols[C] + rr;
var cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) { last_seen = false; continue; }
/* write cell */
last_seen = write_ws_bin_cell(ba, cell, R, C, opts, ws, last_seen, date1904);
@ -19635,7 +19696,13 @@ function write_ws_xlml_cell(cell, ref/*:string*/, ws, opts, idx/*:number*/, wb,
var t = "", p = "";
switch(cell.t) {
case 'z': if(!opts.sheetStubs) return ""; break;
case 'n': t = 'Number'; p = String(cell.v); break;
case 'n': {
if(!isFinite(cell.v)) {
t = 'Error'; p = BErr[isNaN(cell.v) ? 0x24 : 0x07];
} else {
t = 'Number'; p = String(cell.v);
}
} break;
case 'b': t = 'Boolean'; p = (cell.v ? "1" : "0"); break;
case 'e': t = 'Error'; p = BErr[cell.v]; break;
case 'd': t = 'DateTime'; p = new Date(cell.v).toISOString(); if(cell.z == null) cell.z = cell.z || table_fmt[14]; break;
@ -19677,9 +19744,12 @@ function write_ws_xlml_table(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbo
o.push(writextag("Column",null,k));
});
var dense = ws["!data"] != null;
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
@ -19690,7 +19760,6 @@ function write_ws_xlml_table(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbo
break;
}
if(skip) continue;
var addr = {r:R,c:C};
var ref = encode_col(C) + encode_row(R), cell = dense ? (ws["!data"][R]||[])[C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, idx, wb, addr));
}
@ -19714,7 +19783,7 @@ function write_ws_xlml(idx/*:number*/, opts, wb/*:Workbook*/)/*:string*/ {
/* WorksheetOptions */
o.push(write_ws_xlml_wsopts(ws, opts, idx, wb));
if(ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
if(ws && ws["!autofilter"]) o.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
return o.join("");
}
@ -19733,11 +19802,10 @@ function write_xlml(wb, opts)/*:string*/ {
d.push(write_props_xlml(wb, opts));
d.push(write_wb_xlml(wb, opts));
d.push("");
d.push("");
d.push(write_names_xlml(wb, opts));
for(var i = 0; i < wb.SheetNames.length; ++i)
d.push(writextag("Worksheet", write_ws_xlml(i, opts, wb), {"ss:Name":escapexml(wb.SheetNames[i])}));
d[2] = write_sty_xlml(wb, opts);
d[3] = write_names_xlml(wb, opts);
return XML_HEADER + writextag("Workbook", d.join(""), {
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
@ -21923,7 +21991,7 @@ function write_ws_biff2(ba/*:BufArray*/, ws/*:Worksheet*/, idx/*:number*/, opts,
if(range.e.c > 0xFF || range.e.r > 0x3FFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, 0x3FFF);
range.e.r = Math.min(range.e.r, 0x3FFF);
}
var date1904 = (((wb||{}).Workbook||{}).WBProps||{}).date1904;
var row = [], comments = [];
@ -22333,9 +22401,9 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) {
var range = safe_decode_range(ws['!ref'] || "A1");
var MAX_ROWS = b8 ? 65536 : 16384;
if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV" + MAX_ROWS);
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, MAX_ROWS-1);
range.e.r = Math.min(range.e.r, MAX_ROWS-1);
}
write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
@ -22370,12 +22438,11 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) {
if(dense) row = ws["!data"][R] || [];
rr = encode_row(R);
for(C = range.s.c; C <= range.e.c; ++C) {
ref = cols[C] + rr;
var cell = dense ? row[C] : ws[ref];
var cell = dense ? row[C] : ws[cols[C] + rr];
if(!cell) continue;
/* write cell */
write_ws_biff8_cell(ba, cell, R, C, opts, date1904);
if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
if(b8 && cell.l) ws['!links'].push([cols[C] + rr, cell.l]);
if(cell.c) comments.push([cell.c, R, C]);
}
}
@ -22519,6 +22586,9 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(range.e.c > 255) { // note: 255 is IV
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
if(range.e.r > 65535) {
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond row 65536. Data may be lost.");
}
}
var o = opts || {};
@ -22578,6 +22648,8 @@ function html_to_sheet(str/*:string*/, _opts)/*:Workbook*/ {
if(opts.UTC === false) o.v = utc_to_local(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
} else if(m.charCodeAt(0) == 35 /* # */ && RBErr[m] != null) {
o.t = 'e'; o.w = m; o.v = RBErr[m];
}
if(o.cellText !== false) o.w = m;
if(dense) { if(!ws["!data"][R]) ws["!data"][R] = []; ws["!data"][R][C] = o; }
@ -22605,6 +22677,10 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
if(RS < 0) continue;
var coord = encode_col(C) + encode_row(R);
var cell = dense ? (ws["!data"][R]||[])[C] : ws[coord];
if(cell && cell.t == 'n' && cell.v != null && !isFinite(cell.v)) {
if(isNaN(cell.v)) cell = ({t:'e', v:0x24, w:BErr[0x24]});
else cell = ({t:'e', v:0x07, w:BErr[0x07]});
}
/* TODO: html entities */
var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
sp = ({}/*:any*/);
@ -22715,6 +22791,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}
else if(_t == "e" && BErr[+v]) o = {t:'e', v:+v, w: BErr[+v]};
else if(v === 'TRUE') o = {t:'b', v:true};
else if(v === 'FALSE') o = {t:'b', v:false};
else if(!isNaN(fuzzynum(v))) o = {t:'n', v:fuzzynum(v)};
@ -22723,7 +22800,7 @@ function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/
if(opts.UTC) o.v = local_to_utc(o.v);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || table_fmt[14];
}
} else if(v.charCodeAt(0) == 35 /* # */ && RBErr[v] != null) o = ({t:'e', v: RBErr[v], w: v});
}
if(o.z === undefined && z != null) o.z = z;
/* The first link is used. Links are assumed to be fully specified.
@ -23024,7 +23101,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
var Sheets = {}, SheetNames/*:Array<string>*/ = [];
var ws = ({}/*:any*/); if(opts.dense) ws["!data"] = [];
var Rn, q/*:: :any = ({t:"", v:null, z:null, w:"",c:[],}:any)*/;
var ctag = ({value:""}/*:any*/);
var ctag = ({value:""}/*:any*/), ctag2 = ({}/*:any*/);
var textp = "", textpidx = 0, textptag/*:: = {}*/, oldtextp = "", oldtextpidx = 0;
var textR = [], oldtextR = [];
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
@ -23118,6 +23195,7 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
if(R < range.s.r) range.s.r = R;
if(rptR > range.e.r) range.e.r = rptR;
ctag = parsexmltag(Rn[0], false);
ctag2 = parsexmltagraw(Rn[0], true);
comments = []; comment = ({}/*:any*/);
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null/*:: , z:null, w:"",c:[]*/}/*:any*/);
if(ctag["style-name"] && styles[ctag["style-name"]]) q.z = styles[ctag["style-name"]];
@ -23171,6 +23249,9 @@ function parse_content_xml(d/*:string*/, _opts, _nfm)/*:Workbook*/ {
}
} else {
isstub = false;
if(ctag2['calcext:value-type'] == "error" && RBErr[textp] != null) {
q.t = 'e'; q.w = textp; q.v = RBErr[textp];
}
if(q.t === 's') {
q.v = textp || '';
if(textR.length) q.R = textR;
@ -23834,9 +23915,22 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = /* @__PURE__ */(function
ct['office:boolean-value'] = (cell.v ? 'true' : 'false');
break;
case 'n':
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
if(!isFinite(cell.v)) {
if(isNaN(cell.v)) {
textp = "#NUM!";
ct['table:formula'] = "of:=#NUM!";
} else {
textp = "#DIV/0!";
ct['table:formula'] = "of:=" + (cell.v < 0 ? "-" : "") + "1/0";
}
ct['office:string-value'] = "";
ct['office:value-type'] = "string";
ct['calcext:value-type'] = "error";
} else {
textp = (cell.w||String(cell.v||0));
ct['office:value-type'] = "float";
ct['office:value'] = (cell.v||0);
}
break;
case 's': case 'str':
textp = cell.v == null ? "" : cell.v;
@ -27077,6 +27171,8 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{};
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
/* Javet projects `byte[]` to `Int8Array` */
if(typeof Int8Array !== 'undefined' && data instanceof Int8Array) return readSync(new Uint8Array(data.buffer, data.byteOffset, data.length), 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; }
@ -27439,7 +27535,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) {
}
var qreg = /"/g;
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Array<string>*/, fs/*:number*/, rs/*:number*/, FS/*:string*/, w/*:number*/, o/*:Sheet2CSVOpts*/)/*:?string*/ {
var isempty = true;
var row/*:Array<string>*/ = [], txt = "", rr = encode_row(R);
var dense = sheet["!data"] != null;
@ -27452,7 +27548,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
isempty = false;
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; }
if(txt == "ID") txt = '"ID"';
if(txt == "ID" && w == 0 && row.length == 0) txt = '"ID"';
} else if(val.f != null && !val.F) {
isempty = false;
txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"';
@ -27479,7 +27575,7 @@ function sheet_to_csv(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/)/*:string*/ {
var w = 0;
for(var R = r.s.r; R <= r.e.r; ++R) {
if ((rowinfo[R]||{}).hidden) continue;
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, w, o);
if(row == null) { continue; }
if(row || (o.blankrows !== false)) out.push((w++ ? RS : "") + row);
}
@ -27494,7 +27590,7 @@ function sheet_to_txt(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
function sheet_to_formulae(sheet/*:Worksheet*/, opts/*:?Sheet2FormulaOpts*/)/*:Array<string>*/ {
var y = "", x, val="";
if(sheet == null || sheet["!ref"] == null) return [];
var r = safe_decode_range(sheet['!ref']), rr = "", cols/*:Array<string>*/ = [], C;
@ -27515,6 +27611,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
if(y.indexOf(":") == -1) y = y + ":" + y;
}
if(x.f != null) val = x.f;
else if(opts && opts.values === false) continue;
else if(x.t == 'z') continue;
else if(x.t == 'n' && x.v != null) val = "" + x.v;
else if(x.t == 'b') val = x.v ? "TRUE" : "FALSE";
@ -27783,7 +27880,7 @@ function write_csv_stream(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
while(R <= r.e.r) {
++R;
if ((rowinfo[R-1]||{}).hidden) continue;
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, o);
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, w, o);
if(row != null) {
if(row || (o.blankrows !== false)) return stream.push((w++ ? RS : "") + row);
}
@ -27880,10 +27977,165 @@ function write_json_stream(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
return stream;
}
function write_xlml_stream(wb/*:Workbook*/, o/*:?Sheet2XLMLOpts*/) {
var stream = _Readable();
var opts = o == null ? {} : o;
var stride = +opts.stride || 10;
if(!wb.SSF) wb.SSF = dup(table_fmt);
if(wb.SSF) {
make_ssf(); SSF_load_table(wb.SSF);
// $FlowIgnore
opts.revssf = evert_num(wb.SSF); opts.revssf[wb.SSF[65535]] = 0;
opts.ssf = wb.SSF;
opts.cellXfs = [];
get_cell_style(opts.cellXfs, {}, {revssf:{"General":0}});
}
/* do one pass to determine styles since they must be added before tables */
wb.SheetNames.forEach(function(n) {
var ws = wb.Sheets[n];
if(!ws || !ws["!ref"]) return;
var range = decode_range(ws["!ref"]);
var dense = ws["!data"] != null;
var ddata = dense ? ws["!data"] : [];
var addr = {r:0,c:0};
for(var R = range.s.r; R <= range.e.r; ++R) {
addr.r = R;
if(dense && !ddata[R]) continue;
for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var cell = dense ? ddata[R][C] : ws[encode_col(C) + encode_row(R)];
if(!cell) continue;
if(cell.t == "d" && cell.z == null) { cell = dup(cell); cell.z = table_fmt[14]; }
void get_cell_style(opts.cellXfs, cell, opts);
}
}
});
var sty = write_sty_xlml(wb, opts);
var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
stream._read = function() { switch(stage) {
/* header */
case 0: {
stage = 1;
stream.push(XML_HEADER);
stream.push("<Workbook" + wxt_helper({
'xmlns': XLMLNS.ss,
'xmlns:o': XLMLNS.o,
'xmlns:x': XLMLNS.x,
'xmlns:ss': XLMLNS.ss,
'xmlns:dt': XLMLNS.dt,
'xmlns:html': XLMLNS.html
}) + ">");
} break;
/* preamble */
case 1: {
stage = 2;
stream.push(write_props_xlml(wb, opts));
stream.push(write_wb_xlml(wb, opts));
} break;
/* style and name tables */
case 2: {
stage = 3;
stream.push(sty);
stream.push(write_names_xlml(wb, opts));
} break;
/* worksheet preamble */
case 3: {
T = false;
if(wsidx >= wb.SheetNames.length) { stage = -1; stream.push(""); break; }
stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
ws = wb.Sheets[wb.SheetNames[wsidx]];
if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
var names = write_ws_xlml_names(ws, opts, wsidx, wb);
if(names.length) stream.push("<Names>" + names + "</Names>");
if(!ws["!ref"]) return (stage = 5);
range = safe_decode_range(ws["!ref"]);
R = range.s.r;
stage = 4;
} break;
/* worksheet intramble */
case 4: {
if(R < 0 || R > range.e.r) { if(T) stream.push("</Table>"); return void (stage = 5); }
if(R <= range.s.r) {
if(ws['!cols']) ws['!cols'].forEach(function(n, i) {
process_col(n);
var w = !!n.width;
var p = col_obj_w(i, n);
var k/*:any*/ = {"ss:Index":i+1};
if(w) k['ss:Width'] = width2px(p.width);
if(n.hidden) k['ss:Hidden']="1";
if(!T) { T = true; stream.push("<Table>"); }
stream.push(writextag("Column",null,k));
});
dense = ws["!data"] != null;
if(dense) darr = ws["!data"];
addr.r = addr.c = 0;
}
/* process `stride` rows per invocation */
for(var cnt = 0; R <= range.e.r && cnt < stride; ++R, ++cnt) {
var row = [write_ws_xlml_row(R, (ws['!rows']||[])[R])];
addr.r = R;
if(!(dense && !darr[R])) for(var C = range.s.c; C <= range.e.c; ++C) {
addr.c = C;
var skip = false;
for(mi = 0; mi != marr.length; ++mi) {
if(marr[mi].s.c > C) continue;
if(marr[mi].s.r > R) continue;
if(marr[mi].e.c < C) continue;
if(marr[mi].e.r < R) continue;
if(marr[mi].s.c != C || marr[mi].s.r != R) skip = true;
break;
}
if(skip) continue;
var ref = encode_col(C) + encode_row(R), cell = dense ? darr[R][C] : ws[ref];
row.push(write_ws_xlml_cell(cell, ref, ws, opts, wsidx, wb, addr));
}
row.push("</Row>");
if(!T) { T = true; stream.push("<Table>"); }
stream.push(row.join(""));
}
} break;
/* worksheet postamble */
case 5: {
stream.push(write_ws_xlml_wsopts(ws, opts, wsidx, wb));
if(ws && ws["!autofilter"]) stream.push('<AutoFilter x:Range="' + a1_to_rc(fix_range(ws["!autofilter"].ref), {r:0,c:0}) + '" xmlns="urn:schemas-microsoft-com:office:excel"></AutoFilter>');
stream.push("</Worksheet>");
wsidx++; R = -1;
return void (stage = 3);
}
/* footer */
case -1: {
stage = -2;
stream.push("</Workbook>");
} break;
/* exeunt */
case -2: stream.push(null); break;
}};
return stream;
}
var __stream = {
to_json: write_json_stream,
to_html: write_html_stream,
to_csv: write_csv_stream,
to_xlml: write_xlml_stream,
set_readable: set_readable
};
export const version = XLSX.version;