Skip to content

Commit 9c8b9b0

Browse files
committed
updating to XLS 0.6.17, XLSX 0.6.2
1 parent 29842ac commit 9c8b9b0

File tree

1 file changed

+84
-75
lines changed

1 file changed

+84
-75
lines changed

assets/js/xlsx.js

Lines changed: 84 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
/* xlsx.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
22
/* vim: set ts=2: */
3-
/*jshint eqnull:true */
43
var XLSX = {};
54
(function(XLSX){
6-
XLSX.version = '0.6.1';
5+
XLSX.version = '0.6.2';
6+
var current_codepage = 1252, current_cptable;
7+
if(typeof module !== "undefined" && typeof require !== 'undefined') {
8+
if(typeof cptable === 'undefined') cptable = require('codepage');
9+
current_cptable = cptable[current_codepage];
10+
}
11+
function reset_cp() { set_cp(1252); }
12+
function set_cp(cp) { current_codepage = cp; if(typeof cptable !== 'undefined') current_cptable = cptable[cp]; }
13+
14+
var _getchar = function(x) { return String.fromCharCode(x); };
15+
if(typeof cptable !== 'undefined') _getchar = function(x) {
16+
if (current_codepage === 1200) return String.fromCharCode(x);
17+
if (current_cptable) return current_cptable.dec[x];
18+
return cptable.utils.decode(current_codepage, [x%256,x>>8])[0];
19+
};
720
/* ssf.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
821
var SSF = {};
922
var make_ssf = function(SSF){
1023
var _strrev = function(x) { return String(x).split("").reverse().join("");};
1124
function fill(c,l) { return new Array(l+1).join(c); }
1225
function pad(v,d,c){var t=String(v);return t.length>=d?t:(fill(c||0,d-t.length)+t);}
1326
function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
14-
SSF.version = '0.6.4';
27+
SSF.version = '0.6.5';
1528
/* Options */
16-
var opts_fmt = {};
29+
var opts_fmt = {
30+
date1904:0,
31+
output:"",
32+
WTF:false
33+
};
1734
function fixopts(o){for(var y in opts_fmt) if(o[y]===undefined) o[y]=opts_fmt[y];}
1835
SSF.opts = opts_fmt;
19-
opts_fmt.date1904 = 0;
20-
opts_fmt.output = "";
2136
var table_fmt = {
2237
0: 'General',
2338
1: '0',
@@ -95,7 +110,7 @@ var frac = function frac(x, D, mixed) {
95110
var q = Math.floor(sgn * P/Q);
96111
return [q, sgn*P - q*Q, Q];
97112
};
98-
var general_fmt = function(v) {
113+
var general_fmt = function(v, opts) {
99114
if(typeof v === 'boolean') return v ? "TRUE" : "FALSE";
100115
if(typeof v === 'number') {
101116
var o, V = v < 0 ? -v : v;
@@ -106,12 +121,12 @@ var general_fmt = function(v) {
106121
else if(V >= Math.pow(10,10) && V < Math.pow(10,11)) o = v.toFixed(10).substr(0,12);
107122
else if(V > Math.pow(10,-9) && V < Math.pow(10,11)) {
108123
o = v.toFixed(12).replace(/(\.[0-9]*[1-9])0*$/,"$1").replace(/\.$/,"");
109-
if(o.length > 11+(v<0?1:0)) o = v.toPrecision(10);
110-
if(o.length > 11+(v<0?1:0)) o = v.toExponential(5);
124+
if(o.length > (v<0?12:11)) o = v.toPrecision(10);
125+
if(o.length > (v<0?12:11)) o = v.toExponential(5);
111126
}
112127
else {
113128
o = v.toFixed(11).replace(/(\.[0-9]*[1-9])0*$/,"$1");
114-
if(o.length > 11 + (v<0?1:0)) o = v.toPrecision(6);
129+
if(o.length > (v<0?12:11)) o = v.toPrecision(6);
115130
}
116131
o = o.replace(/(\.[0-9]*[1-9])0+e/,"$1e").replace(/\.0*e/,"e");
117132
return o.replace("e","E").replace(/\.0*$/,"").replace(/\.([0-9]*[^0])0*$/,".$1").replace(/(E[+-])([0-9])$/,"$1"+"0"+"$2");
@@ -120,10 +135,12 @@ var general_fmt = function(v) {
120135
throw new Error("unsupported value in General format: " + v);
121136
};
122137
SSF._general = general_fmt;
123-
function fix_hijri(date, o) { }
138+
function fix_hijri(date, o) { return 0; }
124139
var parse_date_code = function parse_date_code(v,opts,b2) {
125140
var date = Math.floor(v), time = Math.floor(86400 * (v - date)+1e-6), dow=0;
126-
var dout=[], out={D:date, T:time, u:86400*(v-date)-time}; fixopts(opts = (opts||{}));
141+
var dout=[];
142+
var out={D:date, T:time, u:86400*(v-date)-time,y:0,m:0,d:0,H:0,M:0,S:0,q:0};
143+
fixopts(opts = (opts||{}));
127144
if(opts.date1904) date += 1462;
128145
if(date > 2958465) return null;
129146
if(out.u > 0.999) {
@@ -152,7 +169,6 @@ var parse_date_code = function parse_date_code(v,opts,b2) {
152169
SSF.parse_date_code = parse_date_code;
153170
/*jshint -W086 */
154171
var write_date = function(type, fmt, val) {
155-
if(val < 0) return "";
156172
var o, ss, y = val.y;
157173
switch(type) {
158174
case 'b': y = val.y + 543;
@@ -224,11 +240,11 @@ var write_num = function(type, fmt, val) {
224240
var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
225241
if(fmt.match(/^#+0.0E\+0$/)) {
226242
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
227-
var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period;
243+
var ee = (Number(val.toExponential(0).substr(2+(val<0?1:0))))%period;
228244
if(ee < 0) ee += period;
229245
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period);
230246
if(!o.match(/[Ee]/)) {
231-
var fakee = (Number(val.toExponential(0).substr(2+(val<0))));
247+
var fakee = (Number(val.toExponential(0).substr(2+(val<0?1:0))));
232248
if(o.indexOf(".") === -1) o = o[0] + "." + o.substr(1) + "E+" + (fakee - o.length+ee);
233249
else o += "E+" + (fakee - ee);
234250
while(o.substr(0,2) === "0.") {
@@ -248,7 +264,7 @@ var write_num = function(type, fmt, val) {
248264
if((r = fmt.match(/# (\?+)([ ]?)\/([ ]?)(\d+)/))) {
249265
var den = Number(r[4]), rnd = Math.round(aval * den), base = Math.floor(rnd/den);
250266
var myn = (rnd - base*den), myd = den;
251-
return sign + (base?base:"") + " " + (myn === 0 ? fill(" ", r[1].length + 1 + r[4].length) : pad(myn,r[1].length," ") + r[2] + "/" + r[3] + pad(myd,r[4].length));
267+
return sign + String(base||"") + " " + (myn === 0 ? fill(" ", r[1].length + 1 + r[4].length) : pad(myn,r[1].length," ") + r[2] + "/" + r[3] + pad(myd,r[4].length));
252268
}
253269
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,"");
254270
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length);
@@ -269,13 +285,10 @@ var write_num = function(type, fmt, val) {
269285
return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(rr,r[1].length,0);
270286
}
271287
if((r = fmt.match(/^#,#*,#0/))) return write_num(type,fmt.replace(/^#,#*,/,""),val);
272-
if((r = fmt.match(/^([0#]+)\\?-([0#]+)$/))) {
273-
ff = write_num(type, fmt.replace(/[\\-]/g,""), val);
274-
return ff.substr(0,ff.length - r[2].length) + "-" + ff.substr(ff.length-r[2].length);
275-
}
276-
if((r = fmt.match(/^([0#]+)\\?-([0#]+)\\?-([0#]+)$/))) {
277-
ff = write_num(type, fmt.replace(/[\\-]/g,""), val);
278-
return ff.substr(0,ff.length - r[2].length - r[3].length) + "-" + ff.substr(ff.length-r[2].length - r[3].length, r[2].length) + "-" + ff.substr(ff.length-r[3].length);
288+
if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/))) {
289+
ff = _strrev(write_num(type, fmt.replace(/[\\-]/g,""), val));
290+
rr = 0;
291+
return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return rr<ff.length?ff[rr++]:x==='0'?'0':'';}));
279292
}
280293
if(fmt.match(/\(###\) ###\\?-####/)) {
281294
ff = write_num(type, "##########", val);
@@ -296,7 +309,7 @@ var write_num = function(type, fmt, val) {
296309
return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function($$) { return "00," + ($$.length < 3 ? pad(0,3-$$.length) : "") + $$; }) + "." + pad(rr,r[1].length,0);
297310
}
298311
switch(fmt) {
299-
case "0": case "#0": return Math.round(val);
312+
case "0": case "#0": return ""+Math.round(val);
300313
case "#,###": var x = commaify(String(Math.round(aval))); return x !== "0" ? sign + x : "";
301314
default:
302315
}
@@ -319,7 +332,7 @@ function split_fmt(fmt) {
319332
}
320333
SSF._split = split_fmt;
321334
function eval_fmt(fmt, v, opts, flen) {
322-
var out = [], o = "", i = 0, c = "", lst='t', q = {}, dt;
335+
var out = [], o = "", i = 0, c = "", lst='t', q, dt;
323336
fixopts(opts = (opts || {}));
324337
var hr='H';
325338
/* Tokenize */
@@ -498,16 +511,6 @@ SSF.get_table = function() { return table_fmt; };
498511
SSF.load_table = function(tbl) { for(var i=0; i!=0x0188; ++i) if(tbl[i]) SSF.load(tbl[i], i); };
499512
};
500513
make_ssf(SSF);
501-
var current_codepage, current_cptable;
502-
if(typeof module !== "undefined" && typeof require !== 'undefined') {
503-
if(typeof cptable === 'undefined') cptable = require('codepage');
504-
current_codepage = 1252; current_cptable = cptable[1252];
505-
}
506-
function reset_cp() {
507-
current_codepage = 1252; if(typeof cptable !== 'undefined') current_cptable = cptable[1252];
508-
}
509-
function _getchar(x) { return String.fromCharCode(x); }
510-
511514
function getdata(data) {
512515
if(!data) return null;
513516
if(data.data) return data.name.substr(-4) !== ".bin" ? data.data : data.data.split("").map(function(x) { return x.charCodeAt(0); });
@@ -543,6 +546,7 @@ if (typeof exports !== 'undefined') {
543546
_fs = require('fs');
544547
}
545548
}
549+
var _chr = function(c) { return String.fromCharCode(c); };
546550
var attregexg=/([\w:]+)=((?:")([^"]*)(?:")|(?:')([^']*)(?:'))/g;
547551
var attregex=/([\w:]+)=((?:")(?:[^"]*)(?:")|(?:')(?:[^']*)(?:'))/;
548552
function parsexmltag(tag) {
@@ -677,8 +681,6 @@ function ReadShift(size, t) {
677681
/* falls through */
678682
case 16: o = this.toString('hex', this.l,this.l+size); break;
679683

680-
/* sbcs and dbcs support continue records in the SST way TODO codepages */
681-
/* TODO: DBCS http://msdn.microsoft.com/en-us/library/cc194788.aspx */
682684
case 'dbcs': size = 2*t; loc = this.l;
683685
for(i = 0; i != t; ++i) {
684686
oo.push(_getchar(__readUInt16LE(this, loc)));
@@ -2231,6 +2233,7 @@ var CustomWBViewDef = {
22312233
yWindow: '0'
22322234
};
22332235
var XMLNS_WB = [
2236+
'http://purl.oclc.org/ooxml/spreadsheetml/main',
22342237
'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
22352238
'http://schemas.microsoft.com/office/excel/2006/main',
22362239
'http://schemas.microsoft.com/office/excel/2006/2'
@@ -3420,33 +3423,47 @@ function readFileSync(data, options) {
34203423
return readSync(data, o);
34213424
}
34223425

3423-
var _chr = function(c) { return String.fromCharCode(c); };
3426+
function decode_row(rowstr) { return Number(unfix_row(rowstr)) - 1; }
3427+
function encode_row(row) { return "" + (row + 1); }
3428+
function fix_row(cstr) { return cstr.replace(/([A-Z]|^)([0-9]+)$/,"$1$$$2"); }
3429+
function unfix_row(cstr) { return cstr.replace(/\$([0-9]+)$/,"$1"); }
34243430

3431+
function decode_col(colstr) { var c = unfix_col(colstr), d = 0, i = 0; for(; i !== c.length; ++i) d = 26*d + c.charCodeAt(i) - 64; return d - 1; }
34253432
function encode_col(col) { var s=""; for(++col; col; col=Math.floor((col-1)/26)) s = _chr(((col-1)%26) + 65) + s; return s; }
3426-
function encode_row(row) { return "" + (row + 1); }
3427-
function encode_cell(cell) { return encode_col(cell.c) + encode_row(cell.r); }
3433+
function fix_col(cstr) { return cstr.replace(/^([A-Z])/,"$$$1"); }
3434+
function unfix_col(cstr) { return cstr.replace(/^\$([A-Z])/,"$1"); }
34283435

3429-
function decode_col(c) { var d = 0, i = 0; for(; i !== c.length; ++i) d = 26*d + c.charCodeAt(i) - 64; return d - 1; }
3430-
function decode_row(rowstr) { return Number(rowstr) - 1; }
34313436
function split_cell(cstr) { return cstr.replace(/(\$?[A-Z]*)(\$?[0-9]*)/,"$1,$2").split(","); }
34323437
function decode_cell(cstr) { var splt = split_cell(cstr); return { c:decode_col(splt[0]), r:decode_row(splt[1]) }; }
3438+
function encode_cell(cell) { return encode_col(cell.c) + encode_row(cell.r); }
3439+
function fix_cell(cstr) { return fix_col(fix_row(cstr)); }
3440+
function unfix_cell(cstr) { return unfix_col(unfix_row(cstr)); }
34333441
function decode_range(range) { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
3434-
function encode_range(range) { return encode_cell(range.s) + ":" + encode_cell(range.e); }
3442+
function encode_range(cs,ce) {
3443+
if(typeof ce === 'undefined' || typeof ce === 'number') return encode_range(cs.s, cs.e);
3444+
if(typeof cs !== 'string') cs = encode_cell(cs); if(typeof ce !== 'string') ce = encode_cell(ce);
3445+
return cs == ce ? cs : cs + ":" + ce;
3446+
}
3447+
3448+
function format_cell(cell, v) {
3449+
if(!cell || !cell.t) return "";
3450+
if(typeof cell.w !== 'undefined') return cell.w;
3451+
if(typeof v === 'undefined') v = cell.v;
3452+
if(typeof cell.z !== 'undefined') try { return (cell.w = SSF.format(cell.z, v)); } catch(e) { }
3453+
if(!cell.XF) return v;
3454+
try { return (cell.w = SSF.format(cell.XF.ifmt||0, v)); } catch(e) { return v; }
3455+
}
34353456

34363457
function sheet_to_row_object_array(sheet, opts){
3437-
var val, row, r, hdr = {}, isempty, R, C;
3458+
var val, row, r, hdr = {}, isempty, R, C, v;
34383459
var out = [];
34393460
opts = opts || {};
34403461
if(!sheet || !sheet["!ref"]) return out;
3441-
r = XLSX.utils.decode_range(sheet["!ref"]);
3462+
r = decode_range(sheet["!ref"]);
34423463
for(R=r.s.r, C = r.s.c; C <= r.e.c; ++C) {
34433464
val = sheet[encode_cell({c:C,r:R})];
34443465
if(!val) continue;
3445-
if(val.w) hdr[C] = val.w;
3446-
else switch(val.t) {
3447-
case 's': case 'str': hdr[C] = val.v; break;
3448-
case 'n': hdr[C] = val.v; break;
3449-
}
3466+
hdr[C] = format_cell(val);
34503467
}
34513468

34523469
for (R = r.s.r + 1; R <= r.e.r; ++R) {
@@ -3456,47 +3473,36 @@ function sheet_to_row_object_array(sheet, opts){
34563473
for (C = r.s.c; C <= r.e.c; ++C) {
34573474
val = sheet[encode_cell({c: C,r: R})];
34583475
if(!val || !val.t) continue;
3459-
if(typeof val.w !== 'undefined' && !opts.raw) { row[hdr[C]] = val.w; isempty = false; }
3460-
else switch(val.t){
3461-
case 's': case 'str': case 'b': case 'n':
3462-
if(typeof val.v !== 'undefined') {
3463-
row[hdr[C]] = val.v;
3464-
isempty = false;
3465-
}
3466-
break;
3467-
case 'e': break; /* throw */
3476+
v = (val || {}).v;
3477+
switch(val.t){
3478+
case 'e': continue;
3479+
case 's': case 'str': break;
3480+
case 'b': case 'n': break;
34683481
default: throw 'unrecognized type ' + val.t;
34693482
}
3483+
if(typeof v !== 'undefined') {
3484+
row[hdr[C]] = opts.raw ? v||val.v : format_cell(val,v);
3485+
isempty = false;
3486+
}
34703487
}
34713488
if(!isempty) out.push(row);
34723489
}
34733490
return out;
34743491
}
34753492

34763493
function sheet_to_csv(sheet, opts) {
3477-
var stringify = function stringify(val) {
3478-
if(!val.t) return "";
3479-
if(typeof val.w !== 'undefined') return val.w;
3480-
switch(val.t){
3481-
case 'n': return String(val.v);
3482-
case 's': case 'str': return typeof val.v !== 'undefined' ? val.v : "";
3483-
case 'b': return val.v ? "TRUE" : "FALSE";
3484-
case 'e': return val.v; /* throw out value in case of error */
3485-
default: throw 'unrecognized type ' + val.t;
3486-
}
3487-
};
34883494
var out = [], txt = "";
34893495
opts = opts || {};
34903496
if(!sheet || !sheet["!ref"]) return "";
3491-
var r = XLSX.utils.decode_range(sheet["!ref"]);
3497+
var r = decode_range(sheet["!ref"]);
34923498
var fs = opts.FS||",", rs = opts.RS||"\n";
34933499

34943500
for(var R = r.s.r; R <= r.e.r; ++R) {
34953501
var row = [];
34963502
for(var C = r.s.c; C <= r.e.c; ++C) {
3497-
var val = sheet[XLSX.utils.encode_cell({c:C,r:R})];
3503+
var val = sheet[encode_cell({c:C,r:R})];
34983504
if(!val) { row.push(""); continue; }
3499-
txt = String(stringify(val));
3505+
txt = String(format_cell(val));
35003506
if(txt.indexOf(fs)!==-1 || txt.indexOf(rs)!==-1 || txt.indexOf('"')!==-1)
35013507
txt = "\"" + txt.replace(/"/g, '""') + "\"";
35023508
row.push(txt);
@@ -3521,7 +3527,7 @@ function get_formulae(ws) {
35213527
return cmds;
35223528
}
35233529

3524-
XLSX.utils = {
3530+
var utils = {
35253531
encode_col: encode_col,
35263532
encode_row: encode_row,
35273533
encode_cell: encode_cell,
@@ -3533,11 +3539,14 @@ XLSX.utils = {
35333539
decode_range: decode_range,
35343540
sheet_to_csv: sheet_to_csv,
35353541
make_csv: sheet_to_csv,
3542+
make_json: sheet_to_row_object_array,
35363543
get_formulae: get_formulae,
3544+
format_cell: format_cell,
35373545
sheet_to_row_object_array: sheet_to_row_object_array
35383546
};
3547+
XLSX.parseZip = parseZip;
35393548
XLSX.read = readSync;
35403549
XLSX.readFile = readFileSync;
3541-
XLSX.parseZip = parseZip;
3550+
XLSX.utils = utils;
35423551
XLSX.SSF = SSF;
35433552
})(typeof exports !== 'undefined' ? exports : XLSX);

0 commit comments

Comments
 (0)