Socket
Socket
Sign inDemoInstall

xlsx

Package Overview
Dependencies
4
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.0 to 0.5.6

bits/70_fbin.js

40

bits/10_ssf.js

@@ -9,3 +9,3 @@ /* Spreadsheet Format -- jump to XLSX for the XLSX code */

function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
SSF.version = '0.5.4';
SSF.version = '0.5.7';
/* Options */

@@ -151,4 +151,3 @@ var opts_fmt = {};

case 'y': case 'yy': return pad(val.y % 100,2);
case 'yyy': case 'yyyy': return pad(val.y % 10000,4);
default: throw 'bad year format: ' + fmt;
default: return pad(val.y % 10000,4);
}

@@ -159,5 +158,4 @@ case 'm': switch(fmt) { /* month */

case 'mmm': return months[val.m-1][1];
case 'mmmm': return months[val.m-1][2];
case 'mmmmm': return months[val.m-1][0];
default: throw 'bad month format: ' + fmt;
default: return months[val.m-1][2];
}

@@ -168,4 +166,3 @@ case 'd': switch(fmt) { /* day */

case 'ddd': return days[val.q][0];
case 'dddd': return days[val.q][1];
default: throw 'bad day format: ' + fmt;
default: return days[val.q][1];
}

@@ -203,3 +200,2 @@ case 'h': switch(fmt) { /* 12-hour */

case 'e': { return val.y; } break;
default: throw 'bad format type ' + type + ' in ' + fmt;
}

@@ -220,5 +216,6 @@ };

var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
if(fmt == '##0.0E+0') {
var period = fmt.length - 5;
if(fmt.match(/^#+0.0E\+0$/)) {
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period;
if(ee < 0) ee += period;
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period);

@@ -228,3 +225,8 @@ if(!o.match(/[Ee]/)) {

if(o.indexOf(".") === -1) o = o[0] + "." + o.substr(1) + "E+" + (fakee - o.length+ee);
else throw "missing E |" + o;
else o += "E+" + (fakee - ee);
while(o.substr(0,2) === "0.") {
o = o[0] + o.substr(2,period) + "." + o.substr(2+period);
o = o.replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0.");
}
o = o.replace(/\+-/,"-");
}

@@ -244,2 +246,3 @@ o = o.replace(/^([+-]?)([0-9]*)\.([0-9]*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; });

}
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,"");
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length);

@@ -334,3 +337,4 @@ if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,"");

o = c;
while(fmt[i++] !== ']') o += fmt[i];
while(fmt[i++] !== ']' && i < fmt.length) o += fmt[i];
if(o.substr(-1) !== ']') throw 'unterminated "[" block: |' + o + '|';
if(o.match(/\[[HhMmSs]*\]/)) {

@@ -356,3 +360,3 @@ if(!dt) dt = parse_date_code(v, opts);

default:
if(",$-+/():!^&'~{}<>=".indexOf(c) === -1)
if(",$-+/():!^&'~{}<>=€".indexOf(c) === -1)
throw 'unrecognized character ' + fmt[i] + ' in ' + fmt;

@@ -375,4 +379,4 @@ out.push({t:'t', v:c}); ++i; break;

switch(out[i].t) {
case 't': case 'T': case ' ': break;
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'A': case 'e': case 'Z':
case 't': case 'T': case ' ': case 'D': break;
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'e': case 'Z':
out[i].v = write_date(out[i].t, out[i].v, dt);

@@ -382,11 +386,10 @@ out[i].t = 't'; break;

var jj = i+1;
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || out[jj].v == '$' || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) {
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || '$€'.indexOf(out[jj].v) > -1 || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) {
out[i].v += out[jj].v;
delete out[jj]; ++jj;
}
out[i].v = write_num(out[i].t, out[i].v, v);
out[i].v = write_num(out[i].t, out[i].v, (flen >1 && v < 0 && i>0 && out[i-1].v == "-" ? -v:v));
out[i].t = 't';
i = jj-1; break;
case 'G': out[i].t = 't'; out[i].v = general_fmt(v,opts); break;
default: console.error(out); throw "unrecognized type " + out[i].t;
}

@@ -401,2 +404,3 @@ }

var l = fmt.length;
if(l<4 && fmt[l-1].indexOf("@")>-1) --l;
switch(fmt.length) {

@@ -403,0 +407,0 @@ case 1: fmt = fmt[0].indexOf("@")>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;

@@ -1,1 +0,1 @@

XLSX.version = '0.5.0';
XLSX.version = '0.5.6';
function getdata(data) {
if(!data) return null;
if(data.data) return data.data;
if(data.data) return data.name.substr(-4) !== ".bin" ? data.data : data.data.split("").map(function(x) { return x.charCodeAt(0); });
if(data.asNodeBuffer && typeof Buffer !== 'undefined' && data.name.substr(-4)===".bin") return data.asNodeBuffer();

@@ -5,0 +5,0 @@ if(data.asBinary && data.name.substr(-4) !== ".bin") return data.asBinary();

@@ -0,1 +1,3 @@

var attregexg=/(\w+)=((?:")([^"]*)(?:")|(?:')([^']*)(?:'))/g;
var attregex=/(\w+)=((?:")(?:[^"]*)(?:")|(?:')(?:[^']*)(?:'))/;
function parsexmltag(tag) {

@@ -5,4 +7,4 @@ var words = tag.split(/\s+/);

if(words.length === 1) return z;
(tag.match(/(\w+)="([^"]*)"/g) || []).map(
function(x){var y=x.match(/(\w+)="([^"]*)"/); z[y[1]] = y[2]; });
(tag.match(attregexg) || []).map(
function(x){var y=x.match(attregex); z[y[1]] = y[2].substr(1,y[2].length-2); });
return z;

@@ -9,0 +11,0 @@ }

@@ -19,36 +19,5 @@ function readIEEE754(buf, idx, isLE, nl, ml) {

function s2a(s) {
if(typeof Buffer !== 'undefined') return new Buffer(s, "binary");
var w = s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
return w;
}
var __toBuffer;
if(typeof Buffer !== "undefined") {
Buffer.prototype.hexlify= function() { return this.toString('hex'); };
Buffer.prototype.utf16le= function(s,e){return this.toString('utf16le',s,e).replace(/\u0000/,'').replace(/[\u0001-\u0006]/,'!');};
Buffer.prototype.utf8 = function(s,e) { return this.toString('utf8',s,e); };
Buffer.prototype.lpstr = function(i) { var len = this.readUInt32LE(i); return len > 0 ? this.utf8(i+4,i+4+len-1) : "";};
Buffer.prototype.lpwstr = function(i) { var len = 2*this.readUInt32LE(i); return this.utf8(i+4,i+4+len-1);};
if(typeof cptable !== "undefined") Buffer.prototype.lpstr = function(i) {
var len = this.readUInt32LE(i);
if(len === 0) return "";
if(typeof current_cptable === "undefined") return this.utf8(i+4,i+4+len-1);
var t = Array(this.slice(i+4,i+4+len-1));
//1console.log("start", this.l, len, t);
var c, j = i+4, o = "", cc;
for(;j!=i+4+len;++j) {
c = this.readUInt8(j);
cc = current_cptable.dec[c];
if(typeof cc === 'undefined') {
c = c*256 + this.readUInt8(++j);
cc = current_cptable.dec[c];
}
if(typeof cc === 'undefined') throw "Unrecognized character " + c.toString(16);
if(c === 0) break;
o += cc;
//1console.log(cc, cc.charCodeAt(0), o, this.l);
}
return o;
};
__toBuffer = function(bufs) { return Buffer.concat(bufs[0]); };

@@ -70,13 +39,3 @@ } else {

var __hexlify = function(b) { return b.map(function(x){return (x<16?"0":"") + x.toString(16);}).join(""); };
var __utf16le = function(b,s,e) { if(b.utf16le) return b.utf16le(s,e); var str = ""; for(var i=s; i<e; i+=2) str += String.fromCharCode(__readUInt16LE(b,i)); return str.replace(/\u0000/,'').replace(/[\u0001-\u0006]/,'!'); };
var __utf8 = function(b,s,e) { if(b.utf8) return b.utf8(s,e); var str = ""; for(var i=s; i<e; i++) str += String.fromCharCode(__readUInt8(b,i)); return str; };
var __lpstr = function(b,i) { if(b.lpstr) return b.lpstr(i); var len = __readUInt32LE(b,i); return len > 0 ? __utf8(b, i+4,i+4+len-1) : "";};
var __lpwstr = function(b,i) { if(b.lpwstr) return b.lpwstr(i); var len = 2*__readUInt32LE(b,i); return __utf8(b, i+4,i+4+len-1);};
function bconcat(bufs) { return (typeof Buffer !== 'undefined') ? Buffer.concat(bufs) : [].concat.apply([], bufs); }
function ReadShift(size, t) {

@@ -93,10 +52,2 @@ var o, w, vv, i, loc; t = t || 'u';

case 'utf8': size = t; o = __utf8(this, this.l, this.l + size); break;
case 'utf16le': size=2*t; o = __utf16le(this, this.l, this.l + size); break;
/* [MS-OLEDS] 2.1.4 LengthPrefixedAnsiString */
case 'lpstr': o = __lpstr(this, this.l); size = 5 + o.length; break;
case 'lpwstr': o = __lpwstr(this, this.l); size = 5 + o.length; if(o[o.length-1] == '\u0000') size += 2; break;
/* sbcs and dbcs support continue records in the SST way TODO codepages */

@@ -106,8 +57,2 @@ /* TODO: DBCS http://msdn.microsoft.com/en-us/library/cc194788.aspx */

for(i = 0; i != t; ++i) {
if(this.lens && this.lens.indexOf(loc) !== -1) {
w = __readUInt8(this, loc);
this.l = loc + 1;
vv = ReadShift.call(this, w ? 'dbcs' : 'sbcs', t-i);
return o + vv;
}
o += _getchar(__readUInt16LE(this, loc));

@@ -119,18 +64,5 @@ loc+=2;

for(i = 0; i != t; ++i) {
if(this.lens && this.lens.indexOf(loc) !== -1) {
w = __readUInt8(this, loc);
this.l = loc + 1;
vv = ReadShift.call(this, w ? 'dbcs' : 'sbcs', t-i);
return o + vv;
}
o += _getchar(__readUInt8(this, loc));
loc+=1;
} break;
case 'cstr': size = 0; o = "";
while((w=__readUInt8(this, this.l + size++))!==0) o+= _getchar(w);
break;
case 'wstr': size = 0; o = "";
while((w=__readUInt16LE(this,this.l +size))!==0){o+= _getchar(w);size+=2;}
size+=2; break;
}

@@ -140,24 +72,9 @@ this.l+=size; return o;

function CheckField(hexstr, fld) {
var b = this.slice(this.l, this.l+hexstr.length/2);
var m = b.hexlify ? b.hexlify() : __hexlify(b);
if(m !== hexstr) throw (fld||"") + 'Expected ' + hexstr + ' saw ' + m;
this.l += hexstr.length/2;
}
function WarnField(hexstr, fld) {
var b = this.slice(this.l, this.l+hexstr.length/2);
var m = b.hexlify ? b.hexlify() : __hexlify(b);
if(m !== hexstr) console.error((fld||"") + 'Expected ' + hexstr +' saw ' + m);
this.l += hexstr.length/2;
}
function prep_blob(blob, pos) {
blob.read_shift = ReadShift.bind(blob);
blob.chk = CheckField;
blob.l = pos || 0;
var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
return [read, chk];
var read = ReadShift.bind(blob);
return [read];
}
function parsenoop(blob, length) { blob.l += length; }
/* [MS-XLSB] 2.1.4 Record */
var recordhopper = function(data, cb) {
var recordhopper = function(data, cb, opts) {
var tmpbyte, cntbyte, length;

@@ -9,7 +9,8 @@ prep_blob(data, data.l || 0);

var R = RecordEnum[RT] || RecordEnum[0xFFFF];
length = tmpbyte = data.read_shift(1);
tmpbyte = data.read_shift(1);
length = tmpbyte & 0x7F;
for(cntbyte = 1; cntbyte <4 && (tmpbyte & 0x80); ++cntbyte) length += ((tmpbyte = data.read_shift(1)) & 0x7F)<<(7*cntbyte);
var d = R.f(data, length);
var d = R.f(data, length, opts);
if(cb(d, R, RT)) return;
}
};

@@ -0,1 +1,7 @@

/* [MS-XLSB] 2.5.143 */
var parse_StrRun = function(data, length) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
};
/* [MS-XLSB] 2.1.7.121 */

@@ -7,6 +13,7 @@ var parse_RichStr = function(data, length) {

var str = parse_XLWideString(data);
var rgsStrRun = [];
var z = {
t: str,
raw:"<t>" + escapexml(str) + "</t>",
r: str
r:"<t>" + escapexml(str) + "</t>",
h: str
};

@@ -16,2 +23,3 @@ if(fRichStr) {

var dwSizeStrRun = data.read_shift(4);
for(var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data));
}

@@ -18,0 +26,0 @@ if(fExtStr) {

@@ -108,3 +108,4 @@ /* Parse a list of <r> tags */

/* 18.4.8 si CT_Rst */
var parse_si = function(x) {
var parse_si = function(x, opts) {
var html = opts ? opts.cellHTML : true;
var z = {};

@@ -116,11 +117,11 @@ if(!x) return null;

z.t = utf8read(unescapexml(x.substr(x.indexOf(">")+1).split(/<\/t>/)[0]));
z.raw = x;
z.r = z.t;
z.r = x;
if(html) z.h = z.t;
}
/* 18.4.4 r CT_RElt (Rich Text Run) */
else if((y = x.match(/<r>/))) {
z.raw = x;
z.r = x;
/* TODO: properly parse (note: no other valid child can have body text) */
z.t = utf8read(unescapexml(x.replace(/<[^>]*>/gm,"")));
z.r = parse_rs(x);
if(html) z.h = parse_rs(x);
}

@@ -133,3 +134,3 @@ /* 18.4.3 phoneticPr CT_PhoneticPr (TODO: needed for Asian support) */

/* 18.4 Shared String Table */
var parse_sst_xml = function(data) {
var parse_sst_xml = function(data, opts) {
var s = [];

@@ -139,3 +140,3 @@ /* 18.4.9 sst CT_Sst */

if(isval(sst)) {
s = sst[2].replace(/<(?:si|sstItem)>/g,"").split(/<\/(?:si|sstItem)>/).map(parse_si).filter(function(x) { return x; });
s = sst[2].replace(/<(?:si|sstItem)>/g,"").split(/<\/(?:si|sstItem)>/).map(function(x) { return parse_si(x, opts); }).filter(function(x) { return x; });
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;

@@ -142,0 +143,0 @@ }

@@ -46,3 +46,3 @@ /* 18.8.31 numFmts CT_NumFmts */

/* 18.8 Styles CT_Stylesheet*/
function parse_styles(data) {
function parse_sty_xml(data) {
/* 18.8.39 styleSheet CT_Stylesheet */

@@ -49,0 +49,0 @@ var t;

@@ -17,3 +17,3 @@ function parse_BrtFmt(data, length) {

for(var y in SSF._table) styles.NumberFmt[y] = SSF._table[y];
styles.CellXf = [];

@@ -20,0 +20,0 @@ var state = "";

@@ -21,2 +21,3 @@

"application/vnd.openxmlformats-officedocument.extended-properties+xml": "extprops",
"application/vnd.openxmlformats-officedocument.custom-properties+xml": "custprops",
"application/vnd.openxmlformats-officedocument.theme+xml":"themes",

@@ -68,2 +69,42 @@ "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml": "comments",

/* 15.2.12.2 Custom File Properties Part */
function parseCustomProps(data) {
var p = {}, name;
data.match(/<[^>]+>([^<]*)/g).forEach(function(x) {
var y = parsexmltag(x);
switch(y[0]) {
case '<property': name = y.name; break;
case '</property>': name = null; break;
default: if (x.indexOf('<vt:') === 0) {
var toks = x.split('>');
var type = toks[0].substring(4), text = toks[1];
/* 22.4.2.32 (CT_Variant). Omit the binary types from 22.4 (Variant Types) */
switch(type) {
case 'lpstr': case 'lpwstr': case 'bstr': case 'lpwstr':
p[name] = unescapexml(text);
break;
case 'bool':
p[name] = parsexmlbool(text, '<vt:bool>');
break;
case 'i1': case 'i2': case 'i4': case 'i8': case 'int': case 'uint':
p[name] = parseInt(text, 10);
break;
case 'r4': case 'r8': case 'decimal':
p[name] = parseFloat(text);
break;
case 'filetime': case 'date':
p[name] = text; // should we make this into a date?
break;
case 'cy': case 'error':
p[name] = unescapexml(text);
break;
default:
console.warn('Unexpected', x, type, toks);
}
}
}
});
return p;
}
/* 18.6 Calculation Chain */

@@ -90,3 +131,3 @@ function parseDeps(data) {

var ct = { workbooks: [], sheets: [], calcchains: [], themes: [], styles: [],
coreprops: [], extprops: [], strs:[], comments: [], xmlns: "" };
coreprops: [], extprops: [], custprops: [], strs:[], comments: [], xmlns: "" };
(data.match(/<[^>]*>/g)||[]).forEach(function(x) {

@@ -93,0 +134,0 @@ var y = parsexmltag(x);

/* 18.7.3 CT_Comment */
function parseComments(data) {
if(data.match(/<comments *\/>/)) {
throw new Error('Not a valid comments xml');
}
function parse_comments_xml(data, opts) {
if(data.match(/<comments *\/>/)) return [];
var authors = [];

@@ -19,5 +17,5 @@ var commentList = [];

var rt = parse_si(textMatch[1]);
comment.raw = rt.raw;
comment.r = rt.r;
comment.t = rt.t;
comment.r = rt.r;
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);

@@ -28,6 +26,6 @@ });

function parseCommentsAddToSheets(zip, dirComments, sheets, sheetRels) {
function parse_comments(zip, dirComments, sheets, sheetRels, opts) {
for(var i = 0; i != dirComments.length; ++i) {
var canonicalpath=dirComments[i];
var comments=parseComments(getdata(getzipfile(zip, canonicalpath.replace(/^\//,''))));
var comments=parse_comments_xml(getdata(getzipfile(zip, canonicalpath.replace(/^\//,''))), opts);
// find the sheets targeted by these comments

@@ -38,7 +36,5 @@ var sheetNames = Object.keys(sheets);

var rels = sheetRels[sheetName];
if (rels) {
if(rels) {
var rel = rels[canonicalpath];
if (rel) {
insertCommentsIntoSheet(sheetName, sheets[sheetName], comments);
}
if(rel) insertCommentsIntoSheet(sheetName, sheets[sheetName], comments);
}

@@ -65,8 +61,8 @@ }

if (!cell.c) {
cell.c = [];
}
cell.c.push({a: comment.author, t: comment.t, raw: comment.raw, r: comment.r});
if (!cell.c) cell.c = [];
var o = {a: comment.author, t: comment.t, r: comment.r};
if(comment.h) o.h = comment.h;
cell.c.push(o);
});
}
/* 18.3 Worksheets */
function parse_worksheet(data) {
function parse_ws_xml(data, opts) {
if(!data) return data;

@@ -27,3 +27,3 @@ /* 18.3.1.99 worksheet CT_Worksheet */

cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
var cref = c.match(/r="([^"]*)"/);
var cref = c.match(/r=["']([^"']*)["']/);
c = "<c " + c;

@@ -34,4 +34,2 @@ if(cref && cref.length == 2) {

}
if(refguess.s.c > idx) refguess.s.c = idx;
if(refguess.e.c < idx) refguess.e.c = idx;
var cell = parsexmltag((c.match(/<c[^>]*>/)||[c])[0]); delete cell[0];

@@ -43,4 +41,9 @@ var d = c.substr(c.indexOf('>')+1);

/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
if(cell.t === undefined && p.v === undefined) { p.t = "str"; p.v = undefined; }
if(cell.t === undefined && p.v === undefined) {
if(!opts.sheetStubs) return;
p.t = "str"; p.v = undefined;
}
else p.t = (cell.t ? cell.t : "n"); // default is "n" in schema
if(refguess.s.c > idx) refguess.s.c = idx;
if(refguess.e.c < idx) refguess.e.c = idx;
switch(p.t) {

@@ -52,2 +55,3 @@ case 'n': p.v = parseFloat(p.v); break;

p.r = strs[sidx].r;
if(opts.cellHTML) p.h = strs[sidx].h;
} break;

@@ -77,4 +81,6 @@ case 'str': if(p.v) p.v = utf8read(p.v); break;

}
try { p.w = SSF.format(fmtid,p.v,_ssfopts); } catch(e) { }
try {
p.w = SSF.format(fmtid,p.v,_ssfopts);
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { }
s[cell.r] = p;

@@ -81,0 +87,0 @@ });

@@ -0,1 +1,2 @@

/* [MS-XLSB] 2.4.718 BrtRowHdr */

@@ -21,2 +22,5 @@ var parse_BrtRowHdr = function(data, length) {

/* [MS-XLSB] 2.4.303 BrtCellBlank */
var parse_BrtCellBlank = parsenoop;
/* [MS-XLSB] 2.4.304 BrtCellBool */

@@ -57,3 +61,3 @@ var parse_BrtCellBool = function(data, length) {

/* [MS-XLSB] 2.4.311 BrtCellRk */
/* [MS-XLSB] 2.4.314 BrtCellSt */
var parse_BrtCellSt = function(data, length) {

@@ -65,24 +69,57 @@ var cell = parse_Cell(data);

/* [MS-XLSB] 2.4.647 BrtFmlaBool */
var parse_BrtFmlaBool = function(data, length, opts) {
var cell = parse_Cell(data);
var value = data.read_shift(1);
var o = [cell, value, 'b'];
if(opts.cellFormula) {
var formula = parse_CellParsedFormula(data, length-9);
o[3] = ""; /* TODO */
}
else data.l += length-9;
return o;
};
/* [MS-XLSB] 2.4.648 BrtFmlaError */
var parse_BrtFmlaError = function(data, length) {
var parse_BrtFmlaError = function(data, length, opts) {
var cell = parse_Cell(data);
var fBool = data.read_shift(1);
data.l += length-9;
return [cell, fBool, 'e'];
var value = data.read_shift(1);
var o = [cell, value, 'e'];
if(opts.cellFormula) {
var formula = parse_CellParsedFormula(data, length-9);
o[3] = ""; /* TODO */
}
else data.l += length-9;
return o;
};
/* [MS-XLSB] 2.4.649 BrtFmlaNum */
var parse_BrtFmlaNum = function(data, length) {
var parse_BrtFmlaNum = function(data, length, opts) {
var cell = parse_Cell(data);
var value = parse_Xnum(data);
data.l += length-16;
return [cell, value, 'n' /*, formula */];
var o = [cell, value, 'n'];
if(opts.cellFormula) {
var formula = parse_CellParsedFormula(data, length - 16);
o[3] = ""; /* TODO */
}
else data.l += length-16;
return o;
};
var parse_BrtCellBlank = parsenoop;
var parse_BrtFmlaBool = parsenoop;
var parse_BrtFmlaString = parsenoop;
/* [MS-XLSB] 2.4.650 BrtFmlaString */
var parse_BrtFmlaString = function(data, length, opts) {
var start = data.l;
var cell = parse_Cell(data);
var value = parse_XLWideString(data);
var o = [cell, value, 'str'];
if(opts.cellFormula) {
var formula = parse_CellParsedFormula(data, start + length - data.l);
o[3] = ""; /* TODO */
}
else data.l = start + length;
return o;
};
/* [MS-XLSB] 2.1.7.61 Worksheet */
var parse_ws_bin = function(data) {
var parse_ws_bin = function(data, opts) {
if(!data) return data;

@@ -94,15 +131,12 @@ var s = {};

var pass = false;
var row, p;
var row, p, cf;
recordhopper(data, function(val, R) {
switch(R.n) {
case 'BrtWsDim': ref = val; break;
case 'BrtRowHdr': row = val; break;
case 'BrtRowHdr':
row = val;
break; // TODO
case 'BrtFmlaError': break; // TODO
case 'BrtFmlaString': break; // TODO
case 'BrtFmlaBool': break; // TODO
case 'BrtFmlaBool':
case 'BrtFmlaError':
case 'BrtFmlaNum':
case 'BrtFmlaString':
case 'BrtCellBool':

@@ -119,7 +153,8 @@ case 'BrtCellError':

case 'e': p.raw = val[1]; p.v = BErr[p.raw]; break;
case 'str': if(p.v) p.v = utf8read(p.v); break;
case 'str': p.v = utf8read(val[1]); break;
}
if(val[3]) p.f = val[3];
if(styles.CellXf[val[0].iStyleRef]) try {
p.w = SSF.format(styles.CellXf[val[0].iStyleRef].ifmt,p.v,_ssfopts);
if(opts.cellFormula && val.length > 3) p.f = val[3];
if((cf = styles.CellXf[val[0].iStyleRef])) try {
p.w = SSF.format(cf.ifmt,p.v,_ssfopts);
if(opts.cellNF) p.z = SSF._table[cf.ifmt];
} catch(e) { }

@@ -131,3 +166,2 @@ s[encode_cell({c:val[0].c,r:row.r})] = p;

case 'BrtFmt': break; // TODO
case 'BrtArrFmla': break; // TODO

@@ -159,5 +193,9 @@ case 'BrtShrFmla': break; // TODO

case 'BrtEndSheet': break; // TODO
case 'BrtBeginMergeCells': break; // TODO
case 'BrtMergeCell': break; // TODO
case 'BrtEndMergeCells': break; // TODO
case 'BrtLegacyDrawing': break; // TODO
//default: if(!pass) throw new Error("Unexpected record " + R.n);
}
});
}, opts);
s["!ref"] = encode_range(ref);

@@ -164,0 +202,0 @@ return s;

@@ -8,3 +8,3 @@ var XMLNS_WB = [

/* 18.2 Workbook */
function parse_workbook(data) {
function parse_wb_xml(data) {
var wb = { AppVersion:{}, WBProps:{}, WBView:[], Sheets:[], CalcPr:{}, xmlns: "" };

@@ -11,0 +11,0 @@ var pass = false;

@@ -28,2 +28,8 @@ /* [MS-XLSB] 2.4.301 BrtBundleSh */

case 'BrtEndBundleShs': break;
case 'BrtBeginFnGroup': break;
case 'BrtEndFnGroup': break;
case 'BrtBeginExternals': break;
case 'BrtSupSelf': break;
case 'BrtExternSheet': break;
case 'BrtEndExternals': break;
case 'BrtName': break;

@@ -39,3 +45,2 @@ case 'BrtCalcProp': break;

case 'BrtEndBook': break;
case '': break;
//default: if(!pass) throw new Error("Unexpected record " + R.n);

@@ -42,0 +47,0 @@ }

@@ -1,11 +0,15 @@

function parse_wb(data, name) {
return name.substr(-4)===".bin" ? parse_wb_bin(data) : parse_workbook(data);
function parse_wb(data, name, opts) {
return name.substr(-4)===".bin" ? parse_wb_bin(data, opts) : parse_wb_xml(data, opts);
}
function parse_ws(data, name) {
return name.substr(-4)===".bin" ? parse_ws_bin(data) : parse_worksheet(data);
function parse_ws(data, name, opts) {
return name.substr(-4)===".bin" ? parse_ws_bin(data, opts) : parse_ws_xml(data, opts);
}
function parse_sty(data, name) {
return name.substr(-4)===".bin" ? parse_sty_bin(data) : parse_styles(data);
function parse_sty(data, name, opts) {
return name.substr(-4)===".bin" ? parse_sty_bin(data, opts) : parse_sty_xml(data, opts);
}
function parse_sst(data, name, opts) {
return name.substr(-4)===".bin" ? parse_sst_bin(data, opts) : parse_sst_xml(data, opts);
}

@@ -1,2 +0,5 @@

function parseZip(zip) {
function parseZip(zip, opts) {
opts = opts || {};
fixopts(opts);
reset_cp();
var entries = Object.keys(zip.files);

@@ -12,9 +15,13 @@ var keys = entries.filter(function(x){return x.substr(-1) != '/';}).sort();

}
strs = {};
if(dir.sst) strs=parse_sst(getdata(getzipfile(zip, dir.sst.replace(/^\//,''))), dir.sst);
styles = {};
if(dir.style) styles = parse_sty(getdata(getzipfile(zip, dir.style.replace(/^\//,''))),dir.style);
if(!opts.bookSheets && !opts.bookProps) {
strs = {};
if(dir.sst) strs=parse_sst(getdata(getzipfile(zip, dir.sst.replace(/^\//,''))), dir.sst, opts);
var wb = parse_wb(getdata(getzipfile(zip, dir.workbooks[0].replace(/^\//,''))), dir.workbooks[0]);
styles = {};
if(dir.style) styles = parse_sty(getdata(getzipfile(zip, dir.style.replace(/^\//,''))),dir.style);
}
var wb = parse_wb(getdata(getzipfile(zip, dir.workbooks[0].replace(/^\//,''))), dir.workbooks[0], opts);
var props = {}, propdata = "";

@@ -26,2 +33,21 @@ try {

} catch(e) { }
var custprops = {};
if(!opts.bookSheets || opts.bookProps) {
if (dir.custprops.length !== 0) try {
propdata = getdata(getzipfile(zip, dir.custprops[0].replace(/^\//,'')));
custprops = parseCustomProps(propdata);
} catch(e) {/*console.error(e);*/}
}
var out = {};
if(opts.bookSheets || opts.bookProps) {
var sheets;
if(props.Worksheets && props.SheetNames.length > 0) sheets=props.SheetNames;
else if(wb.Sheets) sheets = wb.Sheets.map(function(x){ return x.name; });
if(opts.bookProps) { out.Props = props; out.Custprops = custprops; }
if(typeof sheets !== 'undefined') out.SheetNames = sheets;
if(opts.bookSheets ? out.SheetNames : opts.bookProps) return out;
}
var deps = {};

@@ -44,3 +70,3 @@ if(dir.calcchain) deps=parseDeps(getdata(getzipfile(zip, dir.calcchain.replace(/^\//,''))));

relsPath = path.replace(/^(.*)(\/)([^\/]*)$/, "$1/_rels/$3.rels");
sheets[props.SheetNames[i]]=parse_ws(getdata(getzipfile(zip, path)),path);
sheets[props.SheetNames[i]]=parse_ws(getdata(getzipfile(zip, path)),path,opts);
sheetRels[props.SheetNames[i]]=parseRels(getdata(getzipfile(zip, relsPath)), path);

@@ -55,3 +81,3 @@ } catch(e) {}

relsPath = path.replace(/^(.*)(\/)([^\/]*)$/, "$1/_rels/$3.rels");
sheets[props.SheetNames[i]]=parse_ws(getdata(getzipfile(zip, path)),path);
sheets[props.SheetNames[i]]=parse_ws(getdata(getzipfile(zip, path)),path,opts);
sheetRels[props.SheetNames[i]]=parseRels(getdata(getzipfile(zip, relsPath)), path);

@@ -62,3 +88,3 @@ } catch(e) {/*console.error(e);*/}

if(dir.comments) parseCommentsAddToSheets(zip, dir.comments, sheets, sheetRels);
if(dir.comments) parse_comments(zip, dir.comments, sheets, sheetRels, opts);

@@ -69,2 +95,3 @@ return {

Props: props,
Custprops: custprops,
Deps: deps,

@@ -71,0 +98,0 @@ Sheets: sheets,

@@ -12,3 +12,3 @@ function readSync(data, options) {

}
return parseZip(zip);
return parseZip(zip, o);
}

@@ -15,0 +15,0 @@

@@ -15,3 +15,3 @@ var _chr = function(c) { return String.fromCharCode(c); };

function sheet_to_row_object_array(sheet, opts){
var val, row, r, hdr = {}, isempty, R, C, v;
var val, row, r, hdr = {}, isempty, R, C;
var out = [];

@@ -58,8 +58,6 @@ opts = opts || {};

if(!val.t) return "";
if(typeof val.w !== 'undefined') return '"' + val.w.replace(/"/,'""') + '"';
if(typeof val.w !== 'undefined') return val.w;
switch(val.t){
case 'n': return String(val.v);
case 's': case 'str':
if(typeof val.v === 'undefined') return "";
return '"' + val.v.replace(/"/,'""') + '"';
case 's': case 'str': return typeof val.v !== 'undefined' ? val.v : "";
case 'b': return val.v ? "TRUE" : "FALSE";

@@ -74,2 +72,3 @@ case 'e': return val.v; /* throw out value in case of error */

var r = XLSX.utils.decode_range(sheet["!ref"]);
var fs = opts.FS||",", rs = opts.RS||"\n";
for(var R = r.s.r; R <= r.e.r; ++R) {

@@ -80,6 +79,8 @@ var row = [];

if(!val) { row.push(""); continue; }
txt = stringify(val);
row.push(String(txt).replace(/\\r\\n/g,"\n").replace(/\\t/g,"\t").replace(/\\\\/g,"\\").replace("\\\"","\"\""));
txt = String(stringify(val));
if(txt.indexOf(fs)!==-1 || txt.indexOf(rs)!==-1 || txt.indexOf('"')!==-1)
txt = "\"" + txt.replace(/"/g, '""') + "\"";
row.push(txt);
}
out += row.join(opts.FS||",") + (opts.RS||"\n");
out += row.join(fs) + (rs);
}

@@ -96,2 +97,3 @@ return out;

if(x.f) val = x.f;
else if(typeof x.v === 'undefined') continue;
else if(typeof x.v === 'number') val = x.v;

@@ -98,0 +100,0 @@ else val = x.v;

@@ -7,8 +7,2 @@

exports.version = XLSX.version;
exports.main = function(args) {
var zip = XLSX.read(args[0], {type:'file'});
console.log(zip.Sheets);
};
if(typeof module !== 'undefined' && require.main === module)
exports.main(process.argv.slice(2));
}
interface Cell {
v;
t: string;
ixfe: number;
w?: string;
t?: string;
f?: string;
r?: string;
h?: string;
c?: any;
z?: string;
}

@@ -6,0 +11,0 @@

{
"name": "xlsx",
"version": "0.5.0",
"version": "0.5.6",
"author": "sheetjs",

@@ -12,5 +12,5 @@ "description": "XLSB / XLSX / XLSM parser",

"dependencies": {
"ssf":">=0.5.5",
"ssf":"~0.5.6",
"codepage":"",
"jszip":"~0.2.1",
"jszip":"~2.1.0",
"commander":""

@@ -20,2 +20,3 @@ },

"mocha":"",
"uglify-js":"",
"jasmine-node": "x"

@@ -22,0 +23,0 @@ },

@@ -20,10 +20,2 @@ # xlsx

The node version installs a binary `xlsx2csv` which can read XLSX/XLSM/XLSB files and output the contents in various formats. The source is available at `xlsx2csv.njs` in the bin directory.
See <http://oss.sheetjs.com/js-xlsx/> for a browser example.
Note that older versions of IE does not support HTML5 File API, so the base64 mode is provided for testing. On OSX you can get the base64 encoding by running:
$ <target_file.xlsx base64 | pbcopy # the pbcopy puts the content in the clipboard
Simple usage (walks through every cell of every sheet and dumps the values):

@@ -41,2 +33,10 @@

The node version installs a binary `xlsx2csv` which can read XLSX/XLSM/XLSB files and output the contents in various formats. The source is available at `xlsx2csv.njs` in the bin directory.
See <http://oss.sheetjs.com/js-xlsx/> for a browser example.
Note that older versions of IE does not support HTML5 File API, so the base64 mode is provided for testing. On OSX you can get the base64 encoding by running:
$ <target_file.xlsx base64 | pbcopy # the pbcopy puts the content in the clipboard
Some helper functions in `XLSX.utils` generate different views of the sheets:

@@ -48,4 +48,10 @@

## Notes
For more details:
- `bin/xlsx2csv.njs` is a tool for node
- `index.html` is the live demo
- `bits/90_utils.js` contains the logic for generating CSV and JSON from sheets
## Cell Object Description
`.SheetNames` is an ordered list of the sheets in the workbook

@@ -58,14 +64,34 @@

- `.v` returns the raw value of the cell
- `.w` returns the formatted text of the cell
- `.t` returns the type of the cell (constrained to the enumeration `ST_CellType` as documented in page 4215 of ISO/IEC 29500-1:2012(E) )
- `.v` : the raw value of the cell
- `.w` : the formatted text of the cell (if applicable)
- `.t` : the type of the cell (constrained to the enumeration `ST_CellType` as documented in page 4215 of ISO/IEC 29500-1:2012(E) )
- `.f` : the formula of the cell (if applicable)
- `.r` : the rich text encoding of a cell text (if applicable)
- `.h` : an HTML rendering of the rich text (if applicable)
- `.c` : comments associated with the cell
- `.z` : the number format string associated with the cell (if requested)
For dates, `.v` holds the raw date code from the sheet and `.w` holds the text
For more details:
## Options
- `bin/xlsx2csv.njs` is a tool for node
- `index.html` is the live demo
- `bits/90_utils.js` contains the logic for generating CSV and JSON from sheets
The exported `read` and `readFile` functions accept an options argument:
| Option Name | Default | Description |
| :---------- | ------: | :---------- |
| cellFormula | true | Save formulae to the .f field ** |
| cellHTML | true | Parse rich text and save HTML to the .h field |
| cellNF | false | Save number format string to the .z field |
| sheetStubs | false | Create cell objects for stub cells |
| bookProps | false | If true, only parse enough to get book metadata ** |
| bookSheets | false | If true, only parse enough to get the sheet names |
- `cellFormula` only applies to constructing XLSB formulae. XLSX/XLSM formulae
are stored in plaintext, but XLSB formulae are stored in a binary format.
- Even if `cellNF` is false, formatted text (.w) will be generated
- In some cases, sheets may be parsed even if `bookSheets` is false.
- `bookSheets` and `bookProps` combine to give both sets of information
The defaults are enumerated in bits/84_defaults.js
## Tested Environments

@@ -101,2 +127,6 @@

## Contributing
Due to the precarious nature of the Open Specifications Promise, it is very important to ensure code is cleanroom. Consult CONTRIBUTING.md
## XLS Support

@@ -120,2 +150,3 @@

- [MS-XLSB]: Excel (.xlsb) Binary File Format
- [MS-OE376]: Office Implementation Information for ECMA-376 Standards Support

@@ -122,0 +153,0 @@ ## Badges

@@ -7,3 +7,4 @@ /* vim: set ts=2: */

var ex = [".xlsb", ".xlsm", ".xlsx"];
var exp = ex.map(function(x){ return x + ".pending"; });
if(process.env.FMTS) ex=process.env.FMTS.split(":").map(function(x){return x[0]==="."?x:"."+x;});
var exp = ex.map(function(x){ return x + ".pending"; });
function test_file(x){return ex.indexOf(x.substr(-5))>=0||exp.indexOf(x.substr(-13))>=0;}

@@ -83,5 +84,122 @@

assert.equal(ws.B1.c[0].t, "Yegor Kozlov:\r\nfirst cell", "must have the concatenated texts");
assert.equal(ws.B1.c[0].r, '<span style="font-weight: bold;">Yegor Kozlov:</span><span style=""><br/>first cell</span>', "must have the html representation");
assert.equal(ws.B1.c[0].h, '<span style="font-weight: bold;">Yegor Kozlov:</span><span style=""><br/>first cell</span>', "must have the html representation");
assert.equal(ws.B1.c[0].r, '<r><rPr><b/><sz val="8"/><color indexed="81"/><rFont val="Tahoma"/></rPr><t>Yegor Kozlov:</t></r><r><rPr><sz val="8"/><color indexed="81"/><rFont val="Tahoma"/></rPr><t xml:space="preserve">\r\nfirst cell</t></r>', "must have the rich text representation");
assert.equal(ws.B1.c[0].a, "Yegor Kozlov","must have the same author");
});
});
describe('options', function() {
var html_cell_types = ['s'];
before(function() {
XLSX = require('./');
});
it('should generate HTML by default', function() {
var wb = XLSX.readFile('./test_files/comments_stress_test.xlsx');
var ws = wb.Sheets.Sheet1;
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
assert(html_cell_types.indexOf(ws[addr].t) === -1 || ws[addr].h);
});
});
it('should not generate HTML when requested', function() {
var wb = XLSX.readFile('./test_files/comments_stress_test.xlsx', {cellHTML: false});
var ws = wb.Sheets.Sheet1;
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
assert(typeof ws[addr].h === 'undefined');
});
});
it('should generate formulae by default', function() {
var wb = XLSX.readFile('./test_files/formula_stress_test.xlsb');
var found = false;
wb.SheetNames.forEach(function(s) {
var ws = wb.Sheets[s];
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
if(typeof ws[addr].f !== 'undefined') return found = true;
});
});
assert(found);
});
it('should not generate formulae when requested', function() {
var wb = XLSX.readFile('./test_files/formula_stress_test.xlsb', {cellFormula: false});
wb.SheetNames.forEach(function(s) {
var ws = wb.Sheets[s];
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
assert(typeof ws[addr].f === 'undefined');
});
});
});
it('should not generate sheet stubs by default', function() {
var wb = XLSX.readFile('./test_files/merge_cells.xlsx');
assert.throws(function() { wb.Sheets.Merge.A2.v; });
});
it('should generate sheet stubs when requested', function() {
var wb = XLSX.readFile('./test_files/merge_cells.xlsx', {sheetStubs:true});
assert(typeof wb.Sheets.Merge.A2.t !== 'undefined');
});
it('should not generate number formats by default', function() {
var wb = XLSX.readFile('./test_files/number_format.xlsm');
wb.SheetNames.forEach(function(s) {
var ws = wb.Sheets[s];
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
assert(typeof ws[addr].z === 'undefined');
});
});
});
it('should generate number formats when requested', function() {
var wb = XLSX.readFile('./test_files/number_format.xlsm', {cellNF: true});
wb.SheetNames.forEach(function(s) {
var ws = wb.Sheets[s];
Object.keys(ws).forEach(function(addr) {
if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return;
assert(typeof ws[addr].t !== 'n' || typeof ws[addr].z !== 'undefined');
});
});
});
describe('book', function() {
it('bookSheets should not generate sheets', function() {
var wb = XLSX.readFile('./test_files/merge_cells.xlsx', {bookSheets:true});
assert(typeof wb.Sheets === 'undefined');
});
it('bookProps should not generate sheets', function() {
var wb = XLSX.readFile('./test_files/number_format.xlsb', {bookProps:true});
assert(typeof wb.Sheets === 'undefined');
});
it('bookProps && bookSheets should not generate sheets', function() {
var wb = XLSX.readFile('./test_files/LONumbers.xlsx', {bookProps:true, bookSheets:true});
assert(typeof wb.Sheets === 'undefined');
});
});
});
describe('input formats', function() {
it('should read binary strings', function() {
XLSX.read(fs.readFileSync('./test_files/comments_stress_test.xlsb', 'binary'), {type: 'binary'});
XLSX.read(fs.readFileSync('./test_files/comments_stress_test.xlsx', 'binary'), {type: 'binary'});
});
it('should read base64 strings', function() {
XLSX.read(fs.readFileSync('./test_files/comments_stress_test.xlsb', 'base64'), {type: 'base64'});
XLSX.read(fs.readFileSync('./test_files/comments_stress_test.xlsx', 'base64'), {type: 'base64'});
});
});
describe('should have core properties and custom properties parsed', function() {
var wb;
before(function() {
XLSX = require('./');
wb = XLSX.readFile('./test_files/custom_properties.xlsx');
});
it('Must have read the core properties', function() {
assert.equal(wb.Props.Company, 'Vector Inc');
assert.equal(wb.Props.Creator, 'Pony Foo');
});
it('Must have read the custom properties', function() {
assert.equal(wb.Custprops['I am a boolean'], true);
assert.equal(wb.Custprops['Date completed'], '1967-03-09T16:30:00Z');
assert.equal(wb.Custprops.Status, 2);
assert.equal(wb.Custprops.Counter, -3.14);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc