updating to 0.15.6

This commit is contained in:
SheetJS 2020-03-15 03:43:59 -04:00
parent c310488be6
commit e14835d5e9
3 changed files with 136 additions and 65 deletions

28
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

32
xlsx.full.min.js vendored

File diff suppressed because one or more lines are too long

141
xlsx.js
View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.15.5';
XLSX.version = '0.15.6';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -192,7 +192,7 @@ var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
/*jshint -W041 */
var SSF = ({});
var make_ssf = function make_ssf(SSF){
SSF.version = '0.10.2';
SSF.version = '0.10.3';
function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; }
function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
function pad0(v,d){var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;}
@ -356,7 +356,7 @@ function general_fmt(v, opts) {
switch(typeof v) {
case 'string': return v;
case 'boolean': return v ? "TRUE" : "FALSE";
case 'number': return (v|0) === v ? general_fmt_int(v) : general_fmt_num(v);
case 'number': return (v|0) === v ? v.toString(10) : general_fmt_num(v);
case 'undefined': return "";
case 'object':
if(v == null) return "";
@ -736,7 +736,7 @@ function fmt_is_date(fmt) {
while(i < fmt.length) {
switch((c = fmt.charAt(i))) {
case 'G': if(isgeneral(fmt, i)) i+= 6; i++; break;
case '"': for(;(/*cc=*/fmt.charCodeAt(++i)) !== 34 && i < fmt.length;) ++i; ++i; break;
case '"': for(;(/*cc=*/fmt.charCodeAt(++i)) !== 34 && i < fmt.length;){/*empty*/} ++i; break;
case '\\': i+=2; break;
case '_': i+=2; break;
case '@': ++i; break;
@ -845,6 +845,7 @@ function eval_fmt(fmt, v, opts, flen) {
o = c; while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1) o+=fmt.charAt(i);
out[out.length] = {t:'D', v:o}; break;
case ' ': out[out.length] = {t:c, v:c}; ++i; break;
case "$": out[out.length] = {t:'t', v:'$'}; ++i; break;
default:
if(",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(c) === -1) throw new Error('unrecognized character ' + c + ' in ' + fmt);
out[out.length] = {t:'t', v:c}; ++i; break;
@ -1143,7 +1144,7 @@ var DO_NOT_EXPORT_CFB = true;
/* vim: set ts=2: */
/*jshint eqnull:true */
/*exported CFB */
/*global module, require:false, process:false, Buffer:false, Uint8Array:false, Uint16Array:false */
/*global Uint8Array:false, Uint16Array:false */
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
@ -1249,7 +1250,7 @@ CRC32.str = crc32_str;
/* [MS-CFB] v20171201 */
var CFB = (function _CFB(){
var exports = {};
exports.version = '1.1.3';
exports.version = '1.1.4';
/* [MS-CFB] 2.6.4 */
function namecmp(l, r) {
var L = l.split("/"), R = r.split("/");
@ -1580,7 +1581,9 @@ function make_sector_list(sectors, dir_start, fat_addrs, ssz) {
k = (i + dir_start); if(k >= sl) k-=sl;
if(chkd[k]) continue;
buf_chain = [];
var seen = [];
for(j=k; j>=0;) {
seen[j] = true;
chkd[j] = true;
buf[buf.length] = j;
buf_chain.push(sectors[j]);
@ -1589,6 +1592,7 @@ function make_sector_list(sectors, dir_start, fat_addrs, ssz) {
if(ssz < 4 + jj) throw new Error("FAT boundary crossed: " + j + " 4 "+ssz);
if(!sectors[addr]) break;
j = __readInt32LE(sectors[addr], jj);
if(seen[j]) break;
}
sector_list[k] = ({nodes: buf, data:__toBuffer([buf_chain])});
}
@ -2589,7 +2593,7 @@ function blobify(data) {
}
/* write or download file */
function write_dl(fname, payload, enc) {
/*global IE_SaveFile, Blob, navigator, saveAs, URL, document, File, chrome */
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
var data = (enc == "utf8") ? utf8write(payload) : payload;
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
@ -2636,7 +2640,7 @@ function read_binary(path) {
}
function keys(o) {
var ks = Object.keys(o), o2 = [];
for(var i = 0; i < ks.length; ++i) if(o.hasOwnProperty(ks[i])) o2.push(ks[i]);
for(var i = 0; i < ks.length; ++i) if(Object.prototype.hasOwnProperty.call(o, ks[i])) o2.push(ks[i]);
return o2;
}
@ -2741,7 +2745,7 @@ function dup(o) {
if(typeof o != 'object' || o == null) return o;
if(o instanceof Date) return new Date(o.getTime());
var out = {};
for(var k in o) if(o.hasOwnProperty(k)) out[k] = dup(o[k]);
for(var k in o) if(Object.prototype.hasOwnProperty.call(o, k)) out[k] = dup(o[k]);
return out;
}
@ -2935,7 +2939,7 @@ var rencoding = evert(encodings);
// TODO: CP remap (need to read file version to determine OS)
var unescapexml = (function() {
/* 22.4.2.4 bstr (Basic String) */
var encregex = /&(?:quot|apos|gt|lt|amp|#x?([\da-fA-F]+));/g, coderegex = /_x([\da-fA-F]{4})_/g;
var encregex = /&(?:quot|apos|gt|lt|amp|#x?([\da-fA-F]+));/ig, coderegex = /_x([\da-fA-F]{4})_/ig;
return function unescapexml(text) {
var s = text + '', i = s.indexOf("<![CDATA[");
if(i == -1) return s.replace(encregex, function($$, $1) { return encodings[$$]||String.fromCharCode(parseInt($1,$$.indexOf("x")>-1?16:10))||$$; }).replace(coderegex,function(m,c) {return String.fromCharCode(parseInt(c,16));});
@ -3062,7 +3066,7 @@ var htmldecode = (function() {
var entities = [
['nbsp', ' '], ['middot', '·'],
['quot', '"'], ['apos', "'"], ['gt', '>'], ['lt', '<'], ['amp', '&']
].map(function(x) { return [new RegExp('&' + x[0] + ';', "g"), x[1]]; });
].map(function(x) { return [new RegExp('&' + x[0] + ';', "ig"), x[1]]; });
return function htmldecode(str) {
var o = str
// Remove new lines and spaces from start of content
@ -3497,7 +3501,7 @@ function encode_range_xls(r, opts) {
}
}
if(r.s.c == 0 && !r.s.cRel) {
if(r.e.c == (opts.biff >= 12 ? 0xFFFF : 0xFF) && !r.e.cRel) {
if(r.e.c == (opts.biff >= 12 ? 0x3FFF : 0xFF) && !r.e.cRel) {
return (r.s.rRel ? "" : "$") + encode_row(r.s.r) + ":" + (r.e.rRel ? "" : "$") + encode_row(r.e.r);
}
}
@ -3695,6 +3699,12 @@ function write_XLWideString(data, o) {
return _null ? o.slice(0, o.l) : o;
}
/* [MS-XLSB] 2.5.91 */
//function parse_LPWideString(data) {
// var cchCharacters = data.read_shift(2);
// return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, "utf16le");
//}
/* [MS-XLSB] 2.5.143 */
function parse_StrRun(data) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
@ -3828,6 +3838,25 @@ function write_RfX(r, o) {
var parse_UncheckedRfX = parse_RfX;
var write_UncheckedRfX = write_RfX;
/* [MS-XLSB] 2.5.155 UncheckedSqRfX */
//function parse_UncheckedSqRfX(data) {
// var cnt = data.read_shift(4);
// var out = [];
// for(var i = 0; i < cnt; ++i) {
// var rng = parse_UncheckedRfX(data);
// out.push(encode_range(rng));
// }
// return out.join(",");
//}
//function write_UncheckedSqRfX(sqrfx) {
// var parts = sqrfx.split(/\s*,\s*/);
// var o = new_buf(4); o.write_shift(4, parts.length);
// var out = [o];
// parts.forEach(function(rng) {
// out.push(write_UncheckedRfX(safe_decode_range(rng)));
// });
// return bconcat(out);
//}
/* [MS-XLS] 2.5.342 ; [MS-XLSB] 2.5.171 */
/* TODO: error checking, NaN and Infinity values are not valid Xnum */
@ -4062,7 +4091,7 @@ var SpecialProperties = {
};
(function() {
for(var y in SpecialProperties) if(SpecialProperties.hasOwnProperty(y))
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})();
@ -5017,7 +5046,7 @@ function xlml_write_custprops(Props, Custprops) {
var T = 'CustomDocumentProperties';
var o = [];
if(Props) keys(Props).forEach(function(k) {
if(!Props.hasOwnProperty(k)) return;
if(!Object.prototype.hasOwnProperty.call(Props, k)) return;
for(var i = 0; i < CORE_PROPS.length; ++i) if(k == CORE_PROPS[i][1]) return;
for(i = 0; i < EXT_PROPS.length; ++i) if(k == EXT_PROPS[i][1]) return;
for(i = 0; i < BLACKLIST.length; ++i) if(k == BLACKLIST[i]) return;
@ -5030,8 +5059,8 @@ if(!Props.hasOwnProperty(k)) return;
o.push(writextag(escapexmltag(k), m, {"dt:dt":t}));
});
if(Custprops) keys(Custprops).forEach(function(k) {
if(!Custprops.hasOwnProperty(k)) return;
if(Props && Props.hasOwnProperty(k)) return;
if(!Object.prototype.hasOwnProperty.call(Custprops, k)) return;
if(Props && Object.prototype.hasOwnProperty.call(Props, k)) return;
var m = Custprops[k];
var t = "string";
if(typeof m == 'number') { t = "float"; m = String(m); }
@ -5996,7 +6025,7 @@ function write_Window1() {
}
/* [MS-XLS] 2.4.346 TODO */
function parse_Window2(blob, length, opts) {
if(opts && opts.biff >= 2 && opts.biff < 8) return {};
if(opts && opts.biff >= 2 && opts.biff < 5) return {};
var f = blob.read_shift(2);
return { RTL: f & 0x40 };
}
@ -7498,13 +7527,13 @@ var PRN = (function() {
}
cc = [];
for(end in cnt) if ( cnt.hasOwnProperty(end) ) {
for(end in cnt) if ( Object.prototype.hasOwnProperty.call(cnt, end) ) {
cc.push([ cnt[end], end ]);
}
if ( !cc.length ) {
cnt = guess_sep_weights;
for(end in cnt) if ( cnt.hasOwnProperty(end) ) {
for(end in cnt) if ( Object.prototype.hasOwnProperty.call(cnt, end) ) {
cc.push([ cnt[end], end ]);
}
}
@ -8902,7 +8931,7 @@ function parse_fonts(t, styles, themes, opts) {
break;
/* 18.8.29 name CT_FontName */
case '<name': if(y.val) font.name = y.val; break;
case '<name': if(y.val) font.name = utf8read(y.val); break;
case '<name/>': case '</name>': break;
/* 18.8.2 b CT_BooleanProperty */
@ -9141,11 +9170,11 @@ return function parse_sty_xml(data, themes, opts) {
if((t=data.match(bordersRegex))) parse_borders(t, styles, themes, opts);
/* 18.8.9 cellStyleXfs CT_CellStyleXfs ? */
/* 18.8.8 cellStyles CT_CellStyles ? */
/* 18.8.10 cellXfs CT_CellXfs ? */
if((t=data.match(cellXfRegex))) parse_cellXfs(t, styles, opts);
/* 18.8.8 cellStyles CT_CellStyles ? */
/* 18.8.15 dxfs CT_Dxfs ? */
/* 18.8.42 tableStyles CT_TableStyles ? */
/* 18.8.11 colors CT_Colors ? */
@ -9569,6 +9598,13 @@ function write_sty_bin(wb, opts) {
}
RELS.THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
/* Even though theme layout is dk1 lt1 dk2 lt2, true order is lt1 dk1 lt2 dk2 */
var XLSXThemeClrScheme = [
'</a:lt1>', '</a:dk1>', '</a:lt2>', '</a:dk2>',
'</a:accent1>', '</a:accent2>', '</a:accent3>',
'</a:accent4>', '</a:accent5>', '</a:accent6>',
'</a:hlink>', '</a:folHlink>'
];
/* 20.1.6.2 clrScheme CT_ColorScheme */
function parse_clrScheme(t, themes, opts) {
themes.themeElements.clrScheme = [];
@ -9612,7 +9648,7 @@ function parse_clrScheme(t, themes, opts) {
case '<a:hlink>': case '</a:hlink>':
case '<a:folHlink>': case '</a:folHlink>':
if (y[0].charAt(1) === '/') {
themes.themeElements.clrScheme.push(color);
themes.themeElements.clrScheme[XLSXThemeClrScheme.indexOf(y[0])] = color;
color = {};
} else {
color.name = y[0].slice(3, y[0].length - 1);
@ -10351,7 +10387,7 @@ var rc_to_a1 = (function(){
};
})();
var crefregex = /(^|[^._A-Z0-9])([$]?)([A-Z]{1,2}|[A-W][A-Z]{2}|X[A-E][A-Z]|XF[A-D])([$]?)([1-9]\d{0,5}|10[0-3]\d{4}|104[0-7]\d{3}|1048[0-4]\d{2}|10485[0-6]\d|104857[0-6])(?![_.\(A-Za-z0-9])/g;
var crefregex = /(^|[^._A-Z0-9])([$]?)([A-Z]{1,2}|[A-W][A-Z]{2}|X[A-E][A-Z]|XF[A-D])([$]?)(10[0-3]\d{4}|104[0-7]\d{3}|1048[0-4]\d{2}|10485[0-6]\d|104857[0-6]|[1-9]\d{0,5})(?![_.\(A-Za-z0-9])/g;
var a1_to_rc =(function(){
return function a1_to_rc(fstr, base) {
return fstr.replace(crefregex, function($0, $1, $2, $3, $4, $5) {
@ -12870,7 +12906,7 @@ var browser_has_Map = typeof Map !== 'undefined';
function get_sst_id(sst, str, rev) {
var i = 0, len = sst.length;
if(rev) {
if(browser_has_Map ? rev.has(str) : rev.hasOwnProperty(str)) {
if(browser_has_Map ? rev.has(str) : Object.prototype.hasOwnProperty.call(rev, str)) {
var revarr = browser_has_Map ? rev.get(str) : rev[str];
for(; i < revarr.length; ++i) {
if(sst[revarr[i]].t === str) { sst.Count ++; return revarr[i]; }
@ -12885,7 +12921,7 @@ function get_sst_id(sst, str, rev) {
if(!rev.has(str)) rev.set(str, []);
rev.get(str).push(len);
} else {
if(!rev.hasOwnProperty(str)) rev[str] = [];
if(!Object.prototype.hasOwnProperty.call(rev, str)) rev[str] = [];
rev[str].push(len);
}
}
@ -15009,7 +15045,7 @@ if(wb.Workbook.WBProps.CodeName) { workbookPr.codeName = wb.Workbook.WBProps.Cod
if(n.Sheet != null) d.localSheetId = ""+n.Sheet;
if(n.Hidden) d.hidden = "1";
if(!n.Ref) return;
o[o.length] = writextag('definedName', String(n.Ref).replace(/</g, "&lt;").replace(/>/g, "&gt;"), d);
o[o.length] = writextag('definedName', escapexml(n.Ref), d);
});
o[o.length] = "</definedNames>";
}
@ -15525,7 +15561,10 @@ function parse_xlml_data(xml, ss, data, cell, base, styles, csty, row, arrayf, o
if(!cell.t) cell.t = 'n';
break;
case 'Error': cell.t = 'e'; cell.v = RBErr[xml]; if(o.cellText !== false) cell.w = xml; break;
default: cell.t = 's'; cell.v = xlml_fixstr(ss||xml); break;
default:
if(xml == "" && ss == "") { cell.t = 'z'; }
else { cell.t = 's'; cell.v = xlml_fixstr(ss||xml); }
break;
}
safe_format_xlml(cell, nf, o);
if(o.cellFormula !== false) {
@ -16313,7 +16352,9 @@ function write_sty_xlml(wb, opts) {
opts.cellXfs.forEach(function(xf, id) {
var payload = [];
payload.push(writextag('NumberFormat', null, {"ss:Format": escapexml(SSF._table[xf.numFmtId])}));
styles.push(writextag('Style', payload.join(""), {"ss:ID": "s" + (21+id)}));
var o = {"ss:ID": "s" + (21+id)};
styles.push(writextag('Style', payload.join(""), o));
});
return writextag("Styles", styles.join(""));
}
@ -17483,12 +17524,12 @@ function write_xls_props(wb, cfb) {
if(wb.Props) {
Keys = keys(wb.Props);
// $FlowIgnore
for(i = 0; i < Keys.length; ++i) (DocSummaryRE.hasOwnProperty(Keys[i]) ? DSEntries : SummaryRE.hasOwnProperty(Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Props[Keys[i]]]);
for(i = 0; i < Keys.length; ++i) (Object.prototype.hasOwnProperty.call(DocSummaryRE, Keys[i]) ? DSEntries : Object.prototype.hasOwnProperty.call(SummaryRE, Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Props[Keys[i]]]);
}
if(wb.Custprops) {
Keys = keys(wb.Custprops);
// $FlowIgnore
for(i = 0; i < Keys.length; ++i) if(!(wb.Props||{}).hasOwnProperty(Keys[i])) (DocSummaryRE.hasOwnProperty(Keys[i]) ? DSEntries : SummaryRE.hasOwnProperty(Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Custprops[Keys[i]]]);
for(i = 0; i < Keys.length; ++i) if(!Object.prototype.hasOwnProperty.call((wb.Props||{}), Keys[i])) (Object.prototype.hasOwnProperty.call(DocSummaryRE, Keys[i]) ? DSEntries : Object.prototype.hasOwnProperty.call(SummaryRE, Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Custprops[Keys[i]]]);
}
var CEntries2 = [];
for(i = 0; i < CEntries.length; ++i) {
@ -18843,6 +18884,29 @@ function write_biff_rec(ba, type, payload, length) {
if(len > 0 && is_buf(payload)) ba.push(payload);
}
//function write_biff_continue(ba, type, payload, length) {
// var len = length || (payload||[]).length || 0;
// if(len <= 8224) return write_biff_rec(ba, type, payload, len);
// var t = +type || +XLSRE[type];
// if(isNaN(t)) return;
// var parts = payload.parts || [], sidx = 0;
// var i = 0, w = 0;
// while(w + (parts[sidx] || 8224) <= 8224) { w+= (parts[sidx] || 8224); sidx++; }
// var o = ba.next(4);
// o.write_shift(2, t);
// o.write_shift(2, w);
// ba.push(payload.slice(i, i + w));
// i += w;
// while(i < len) {
// o = ba.next(4);
// o.write_shift(2, 0x3c); // TODO: figure out correct continue type
// w = 0;
// while(w + (parts[sidx] || 8224) <= 8224) { w+= (parts[sidx] || 8224); sidx++; }
// o.write_shift(2, w);
// ba.push(payload.slice(i, i+w)); i+= w;
// }
//}
function write_BIFF2Cell(out, r, c) {
if(!out) out = new_buf(7);
out.write_shift(2, r);
@ -19568,6 +19632,7 @@ var parse_content_xml = (function() {
if(atag.Target) q.l = atag;
if(comments.length > 0) { q.c = comments; comments = []; }
if(textp && opts.cellText !== false) q.w = textp;
if(isstub) { q.t = "z"; delete q.v; }
if(!isstub || opts.sheetStubs) {
if(!(opts.sheetRows && opts.sheetRows <= R)) {
for(var rpt = 0; rpt < rowpeat; ++rpt) {
@ -20059,6 +20124,11 @@ var write_content_ods = (function() {
o.push(' <number:text>/</number:text>\n');
o.push(' <number:year/>\n');
o.push(' </number:date-style>\n');
o.push(' <style:style style:name="ta1" style:family="table">\n'); // style:master-page-name="mp1">\n');
o.push(' <style:table-properties table:display="true" style:writing-mode="lr-tb"/>\n');
o.push(' </style:style>\n');
o.push(' <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N37"/>\n');
o.push(' </office:automatic-styles>\n');
};
@ -20682,7 +20752,7 @@ function readSync(data, opts) {
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), opts);
var d = data, n = [0,0,0,0], str = false;
var o = opts||{};
if(o.cellStyles) { o.cellNF = true; }
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
_ssfopts = {};
if(o.dateNF) _ssfopts.dateNF = o.dateNF;
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
@ -20727,7 +20797,6 @@ function write_cfb_ctr(cfb, o) {
return CFB.write(cfb, o);
}
/*global encrypt_agile */
function write_zip_type(wb, opts) {
var o = opts||{};
var z = write_zip(wb, o);
@ -20743,7 +20812,9 @@ function write_zip_type(wb, opts) {
default: throw new Error("Unrecognized type " + o.type);
}
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: {"nodebuffer": "buffer", "string": "binary"}[oopts.type] || oopts.type}) : z.generate(oopts);
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o);
/*jshint -W083 */
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef
/*jshint +W083 */
if(o.type === "file") return write_dl(o.file, out);
return o.type == "string" ? utf8read(out) : out;
}
@ -20804,7 +20875,7 @@ function writeSync(wb, opts) {
reset_cp();
check_wb(wb);
var o = opts||{};
if(o.cellStyles) { o.cellNF = true; }
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
if(o.type == "array") { o.type = "binary"; var out = (writeSync(wb, o)); o.type = "array"; return s2ab(out); }
switch(o.bookType || 'xlsb') {
case 'xml':
@ -20868,7 +20939,7 @@ function writeFileAsync(filename, wb, opts, cb) {
}
function make_json_row(sheet, r, R, cols, header, hdr, dense, o) {
var rr = encode_row(R);
var defval = o.defval, raw = o.raw || !o.hasOwnProperty("raw");
var defval = o.defval, raw = o.raw || !Object.prototype.hasOwnProperty.call(o, "raw");
var isempty = true;
var row = (header === 1) ? [] : {};
if(header !== 1) {