Skip to content

Commit

Permalink
version bump 0.11.3: "array" type
Browse files Browse the repository at this point in the history
- phased out Array map invocations (fixes SheetJS#620 h/t @dullin)
- "array" type supports Uint8Array
- Headless browser examples
- blank cells are omitted or stubbed (fixes SheetJS#779 h/t @Domxa)
- removed transferrables from demo
  • Loading branch information
SheetJSDev authored and saarCiklum committed Aug 20, 2020
1 parent 761afc3 commit ebeec97
Show file tree
Hide file tree
Showing 67 changed files with 1,460 additions and 1,641 deletions.
4 changes: 0 additions & 4 deletions .flowconfig
Expand Up @@ -15,17 +15,13 @@

.*/xlsx.js
.*/xlsxworker.js
.*/xlsxworker1.js
.*/xlsxworker2.js
.*/jszip.js
.*/tests/.*
.*/demos/.*

#.*/xlsx.flow.js
[include]
xlsxworker.flow.js
xlsxworker1.flow.js
xlsxworker2.flow.js
xlsx.flow.js
.*/bin/.*.njs
.*/demo/browser.flow.js
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -12,7 +12,7 @@ DEPS=$(sort $(wildcard bits/*.js))
TARGET=$(LIB).js
FLOWTARGET=$(LIB).flow.js
FLOWAUX=$(patsubst %.js,%.flow.js,$(AUXTARGETS))
AUXSCPTS=xlsxworker1.js xlsxworker2.js xlsxworker.js
AUXSCPTS=xlsxworker.js
FLOWTGTS=$(TARGET) $(AUXTARGETS) $(AUXSCPTS)
UGLIFYOPTS=--support-ie8 -m
CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -183,7 +183,7 @@ The `demos` directory includes sample projects for:

**JS Platforms and Integrations**
- [`Adobe ExtendScript`](demos/extendscript/)
- [`phantomjs`](demos/phantomjs/)
- [`Headless Browsers`](demos/headless/)
- [`canvas-datagrid`](demos/datagrid/)
- [`Other JS engines`](demos/altjs/)

Expand Down Expand Up @@ -1432,7 +1432,7 @@ tells the library how to parse the data argument:
| `type` | expected input |
|------------|-----------------------------------------------------------------|
| `"base64"` | string: base64 encoding of the file |
| `"binary"` | string: binary string (`n`-th byte is `data.charCodeAt(n)`) |
| `"binary"` | string: binary string (`n`-th byte is `data.charCodeAt(n)`) |
| `"buffer"` | nodejs Buffer |
| `"array"` | array: array of 8-bit unsigned int (`n`-th byte is `data[n]`) |
| `"file"` | string: filename that will be read and processed (nodejs only) |
Expand All @@ -1458,7 +1458,7 @@ file but Excel will know how to handle it. This library applies similar logic:
| `0xEF` | UTF8 Encoded | SpreadsheetML / Flat ODS / UOS1 / HTML / plaintext |
| `0xFF` | UTF16 Encoded | SpreadsheetML / Flat ODS / UOS1 / HTML / plaintext |
| `0x00` | Record Stream | Lotus WK\* or Quattro Pro or plaintext |
| `0x0A` | Plaintext | RTF or plaintext |
| `0x7B` | Plaintext | RTF or plaintext |
| `0x0A` | Plaintext | SpreadsheetML / Flat ODS / UOS1 / HTML / plaintext |
| `0x0D` | Plaintext | SpreadsheetML / Flat ODS / UOS1 / HTML / plaintext |
| `0x20` | Plaintext | SpreadsheetML / Flat ODS / UOS1 / HTML / plaintext |
Expand Down
2 changes: 1 addition & 1 deletion bits/01_version.js
@@ -1 +1 @@
XLSX.version = '0.11.2';
XLSX.version = '0.11.3';
14 changes: 7 additions & 7 deletions bits/23_binutils.js
Expand Up @@ -28,8 +28,8 @@ var __toBuffer, ___toBuffer;
__toBuffer = ___toBuffer = function toBuffer_(bufs) { var x = []; for(var i = 0; i < bufs[0].length; ++i) { x.push.apply(x, bufs[0][i]); } return x; };
var __utf16le, ___utf16le;
__utf16le = ___utf16le = function utf16le_(b,s,e) { var ss=[]; for(var i=s; i<e; i+=2) ss.push(String.fromCharCode(__readUInt16LE(b,i))); return ss.join(""); };
var __hexlify, ___hexlify;
__hexlify = ___hexlify = function hexlify_(b,s,l) { return b.slice(s,(s+l)).map(function(x){return (x<16?"0":"") + x.toString(16);}).join(""); };
var __hexlify = function(b/*:RawBytes|CFBlob*/,s/*:number*/,l/*:number*/)/*:string*/ { var ss/*:Array<string>*/=[]; for(var i=s; i<s+l; ++i) ss.push(("0" + b[i].toString(16)).slice(-2)); return ss.join(""); };
var ___hexlify = __hexlify;
var __utf8, ___utf8;
__utf8 = ___utf8 = function(b,s,e) { var ss=[]; for(var i=s; i<e; i++) ss.push(String.fromCharCode(__readUInt8(b,i))); return ss.join(""); };
var __lpstr, ___lpstr;
Expand Down Expand Up @@ -68,11 +68,11 @@ if(typeof cptable !== 'undefined') {
__8lpp4 = function(b,i) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
}

var __readUInt8 = function(b, idx) { return b[idx]; };
var __readUInt16LE = function(b, idx) { return b[idx+1]*(1<<8)+b[idx]; };
var __readInt16LE = function(b, idx) { var u = b[idx+1]*(1<<8)+b[idx]; return (u < 0x8000) ? u : (0xffff - u + 1) * -1; };
var __readUInt32LE = function(b, idx) { return b[idx+3]*(1<<24)+(b[idx+2]<<16)+(b[idx+1]<<8)+b[idx]; };
var __readInt32LE = function(b, idx) { return (b[idx+3]<<24)|(b[idx+2]<<16)|(b[idx+1]<<8)|b[idx]; };
var __readUInt8 = function(b, idx/*:number*/)/*:number*/ { return b[idx]; };
var __readUInt16LE = function(b, idx/*:number*/)/*:number*/ { return b[idx+1]*(1<<8)+b[idx]; };
var __readInt16LE = function(b, idx/*:number*/)/*:number*/ { var u = b[idx+1]*(1<<8)+b[idx]; return (u < 0x8000) ? u : (0xffff - u + 1) * -1; };
var __readUInt32LE = function(b, idx/*:number*/)/*:number*/ { return b[idx+3]*(1<<24)+(b[idx+2]<<16)+(b[idx+1]<<8)+b[idx]; };
var __readInt32LE = function(b, idx/*:number*/)/*:number*/ { return (b[idx+3]<<24)|(b[idx+2]<<16)|(b[idx+1]<<8)|b[idx]; };

var ___unhexlify = function(s) { return s.match(/../g).map(function(x) { return parseInt(x,16);}); };
var __unhexlify = typeof Buffer !== "undefined" ? function(s) { return Buffer.isBuffer(s) ? new Buffer(s, 'hex') : ___unhexlify(s); } : ___unhexlify;
Expand Down
4 changes: 2 additions & 2 deletions bits/40_harb.js
Expand Up @@ -518,8 +518,8 @@ var PRN = (function() {
if((cc=str.charCodeAt(end)) == 0x22) instr = !instr;
else if(!instr) cnt[cc] = (cnt[cc]||0)+1;
}
if(cnt[0x2C] > cnt[0x09]) return ",";
return ",";
if((cnt[0x2C]||0) >= (cnt[0x09]||0)) return ",";
return "\t";
}

function dsv_to_sheet_str(str/*:string*/, opts)/*:Worksheet*/ {
Expand Down
22 changes: 21 additions & 1 deletion bits/53_ccbin.js → bits/52_calcchain.js
@@ -1,3 +1,23 @@
/* 18.6 Calculation Chain */
function parse_cc_xml(data, name, opts) {
var d = [];
if(!data) return d;
var l = 0, i = 1;
(data.match(tagregex)||[]).forEach(function(x) {
var y = parsexmltag(x);
switch(y[0]) {
case '<?xml': break;
/* 18.6.2 calcChain CT_CalcChain 1 */
case '<calcChain': case '<calcChain>': case '</calcChain>': break;
/* 18.6.1 c CT_CalcCell 1 */
case '<c': delete y[0]; if(y.i) i = y.i; else y.i = i; d.push(y); break;
}
});
return d;
}

function write_cc_xml(data, opts) { }

/* [MS-XLSB] 2.6.4.1 */
function parse_BrtCalcChainItem$(data, length) {
var out = {};
Expand All @@ -13,7 +33,7 @@ function parse_BrtCalcChainItem$(data, length) {
}

/* 18.6 Calculation Chain */
function parse_cc_bin(data, opts) {
function parse_cc_bin(data, name, opts) {
var out = [];
var pass = false;
recordhopper(data, function hopper_cc(val, R_n, RT) {
Expand Down
19 changes: 0 additions & 19 deletions bits/52_ccxml.js

This file was deleted.

51 changes: 51 additions & 0 deletions bits/53_externlink.js
@@ -0,0 +1,51 @@
/* 18.14 Supplementary Workbook Data */
function parse_xlink_xml(data, name/*:string*/, _opts) {
var opts = _opts || {};
//if(opts.WTF) throw "XLSX External Link";
}

/* [MS-XLSB] 2.1.7.25 External Link */
function parse_xlink_bin(data, name/*:string*/, _opts) {
if(!data) return data;
var opts = _opts || {};

var pass = false, end = false;

recordhopper(data, function xlink_parse(val, R_n, RT) {
if(end) return;
switch(RT) {
case 0x0167: /* 'BrtSupTabs' */
case 0x016B: /* 'BrtExternTableStart' */
case 0x016C: /* 'BrtExternTableEnd' */
case 0x016E: /* 'BrtExternRowHdr' */
case 0x016F: /* 'BrtExternCellBlank' */
case 0x0170: /* 'BrtExternCellReal' */
case 0x0171: /* 'BrtExternCellBool' */
case 0x0172: /* 'BrtExternCellError' */
case 0x0173: /* 'BrtExternCellString' */
case 0x01D8: /* 'BrtExternValueMeta' */
case 0x0241: /* 'BrtSupNameStart' */
case 0x0242: /* 'BrtSupNameValueStart' */
case 0x0243: /* 'BrtSupNameValueEnd' */
case 0x0244: /* 'BrtSupNameNum' */
case 0x0245: /* 'BrtSupNameErr' */
case 0x0246: /* 'BrtSupNameSt' */
case 0x0247: /* 'BrtSupNameNil' */
case 0x0248: /* 'BrtSupNameBool' */
case 0x0249: /* 'BrtSupNameFmla' */
case 0x024A: /* 'BrtSupNameBits' */
case 0x024B: /* 'BrtSupNameEnd' */
break;

case 0x0023: /* 'BrtFRTBegin' */
pass = true; break;
case 0x0024: /* 'BrtFRTEnd' */
pass = false; break;

default:
if((R_n||"").indexOf("Begin") > 0){/* empty */}
else if((R_n||"").indexOf("End") > 0){/* empty */}
else if(!pass || opts.WTF) throw new Error("Unexpected record " + RT.toString(16) + " " + R_n);
}
}, opts);
}
2 changes: 1 addition & 1 deletion bits/62_fxls.js
Expand Up @@ -823,7 +823,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
case 'PtgArea3d': /* 2.5.198.28 TODO */
type = f[1][0]; ixti = /*::Number(*/f[1][1]/*::)*/; r = f[1][2];
sname = (supbooks && supbooks[1] ? supbooks[1][ixti+1] : "**MISSING**");
stack.push(sname + "!" + encode_range((r/*:any*/)));
stack.push(sname + "!" + encode_range_xls((r/*:any*/), opts));
break;
case 'PtgAttrSum': /* 2.5.198.41 */
stack.push("SUM(" + stack.pop() + ")");
Expand Down
9 changes: 7 additions & 2 deletions bits/74_xmlbin.js
Expand Up @@ -43,8 +43,13 @@ function parse_cmnt(data, name/*:string*/, opts) {
}

function parse_cc(data, name/*:string*/, opts) {
if(name.slice(-4)===".bin") return parse_cc_bin((data/*:any*/), opts);
return parse_cc_xml((data/*:any*/), opts);
if(name.slice(-4)===".bin") return parse_cc_bin((data/*:any*/), name, opts);
return parse_cc_xml((data/*:any*/), name, opts);
}

function parse_xlink(data, name/*:string*/, opts) {
if(name.slice(-4)===".bin") return parse_xlink_bin((data/*:any*/), name, opts);
return parse_xlink_xml((data/*:any*/), name, opts);
}

function write_wb(wb, name/*:string*/, opts) {
Expand Down
6 changes: 5 additions & 1 deletion bits/75_xlml.js
Expand Up @@ -377,6 +377,7 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ {
case 'ContentStatus':
case 'Identifier':
case 'Language':
case 'AppName':
if(Rn[0].slice(-2) === "/>") break;
else if(Rn[1]==="/") xlml_set_prop(Props, Rn[3], str.slice(pidx, Rn.index));
else pidx = Rn.index + Rn[0].length;
Expand Down Expand Up @@ -817,7 +818,10 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ {
return out;
}

function arr2str(data/*:any*/)/*:string*/ { return data.map(_chr).join(""); }
function arr2str(data/*:any*/)/*:string*/ {
if(Array.isArray(data)) return data.map(_chr).join("");
var o = []; for(var i = 0; i < data.length; ++i) o[i] = _chr(data[i]); return o.join("");
}

function parse_xlml(data/*:RawBytes|string*/, opts)/*:Workbook*/ {
fix_read_opts(opts=opts||{});
Expand Down
6 changes: 6 additions & 0 deletions bits/76_xls.js
Expand Up @@ -833,6 +833,12 @@ if(cfb.FullPaths) {
Summary = CFB.find(cfb, '!SummaryInformation');
WB = CFB.find(cfb, '/Workbook');
} else {
switch(options.type) {
case 'base64': cfb = s2a(Base64.decode(cfb)); break;
case 'binary': cfb = s2a(cfb); break;
case 'buffer': break;
case 'array': if(!Array.isArray(cfb)) cfb = Array.prototype.slice.call(cfb); break;
}
prep_blob(cfb, 0);
WB = ({content: cfb}/*:any*/);
}
Expand Down
24 changes: 15 additions & 9 deletions bits/85_parsezip.js
Expand Up @@ -38,6 +38,8 @@ function safe_parse_sheet(zip, path/*:string*/, relsPath/*:string*/, sheet, shee
}

var nodirs = function nodirs(x/*:string*/)/*:boolean*/{return x.slice(-1) != '/';};
function strip_front_slash(x/*:string*/)/*:string*/ { return x.charAt(0) == '/' ? x.slice(1) : x; }

function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
make_ssf(SSF);
opts = opts || {};
Expand Down Expand Up @@ -70,7 +72,7 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var styles = ({}/*:any*/);
if(!opts.bookSheets && !opts.bookProps) {
strs = [];
if(dir.sst) strs=parse_sst(getzipdata(zip, dir.sst.replace(/^\//,'')), dir.sst, opts);
if(dir.sst) strs=parse_sst(getzipdata(zip, strip_front_slash(dir.sst)), dir.sst, opts);

// parse themes before styles so that we can reliably decode theme/tint into rgb when parsing styles
themes = {};
Expand All @@ -81,26 +83,30 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {

if(opts.cellStyles && dir.themes.length) themes = parse_theme(getzipstr(zip, dir.themes[0].replace(/^\//,''), true)||"",dir.themes[0], opts);

if(dir.style) styles = parse_sty(getzipdata(zip, dir.style.replace(/^\//,'')),dir.style, themes, opts);
if(dir.style) styles = parse_sty(getzipdata(zip, strip_front_slash(dir.style)), dir.style, themes, opts);
}

var wb = parse_wb(getzipdata(zip, dir.workbooks[0].replace(/^\//,'')), dir.workbooks[0], opts);
var externbooks = dir.links.map(function(link) {
return parse_xlink(getzipdata(zip, strip_front_slash(link)), link, opts);
});

var wb = parse_wb(getzipdata(zip, strip_front_slash(dir.workbooks[0])), dir.workbooks[0], opts);

var props = {}, propdata = "";

if(dir.coreprops.length !== 0) {
propdata = getzipstr(zip, dir.coreprops[0].replace(/^\//,''), true);
if(dir.coreprops.length) {
propdata = getzipstr(zip, strip_front_slash(dir.coreprops[0]), true);
if(propdata) props = parse_core_props(propdata);
if(dir.extprops.length !== 0) {
propdata = getzipstr(zip, dir.extprops[0].replace(/^\//,''), true);
propdata = getzipstr(zip, strip_front_slash(dir.extprops[0]), true);
if(propdata) parse_ext_props(propdata, props, opts);
}
}

var custprops = {};
if(!opts.bookSheets || opts.bookProps) {
if (dir.custprops.length !== 0) {
propdata = getzipstr(zip, dir.custprops[0].replace(/^\//,''), true);
propdata = getzipstr(zip, strip_front_slash(dir.custprops[0]), true);
if(propdata) custprops = parse_cust_props(propdata, opts);
}
}
Expand All @@ -116,7 +122,7 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
sheets = {};

var deps = {};
if(opts.bookDeps && dir.calcchain) deps=parse_cc(getzipdata(zip, dir.calcchain.replace(/^\//,'')),dir.calcchain,opts);
if(opts.bookDeps && dir.calcchain) deps=parse_cc(getzipdata(zip, strip_front_slash(dir.calcchain)),dir.calcchain,opts);

var i=0;
var sheetRels = ({}/*:any*/);
Expand Down Expand Up @@ -170,7 +176,7 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
out.files = zip.files;
}
if(opts.bookVBA) {
if(dir.vba.length > 0) out.vbaraw = getzipdata(zip,dir.vba[0].replace(/^\//,''),true);
if(dir.vba.length > 0) out.vbaraw = getzipdata(zip,strip_front_slash(dir.vba[0]),true);
else if(dir.defaults && dir.defaults.bin === 'application/vnd.ms-office.vbaProject') out.vbaraw = getzipdata(zip,'xl/vbaProject.bin',true);
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion bits/87_read.js
Expand Up @@ -69,7 +69,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
if(o.type == "file") { o.type = "buffer"; d = _fs.readFileSync(data); }
switch((n = firstbyte(d, o))[0]) {
case 0xD0: return read_cfb(CFB.read(d, o), o);
case 0x09: return parse_xlscfb(s2a(o.type === 'base64' ? Base64.decode(d) : d), o);
case 0x09: return parse_xlscfb(d, o);
case 0x3C: return parse_xlml(d, o);
case 0x49: if(n[1] == 0x44) return read_wb_ID(d, o); break;
case 0x54: if(n[1] == 0x41 && n[2] == 0x42 && n[3] == 0x4C) return DIF.to_workbook(d, o); break;
Expand Down

0 comments on commit ebeec97

Please sign in to comment.