version bump 0.17.2: basic node/browser ESM

This commit is contained in:
SheetJS 2021-09-15 21:50:33 -04:00
parent 6c0ada1790
commit 6670c8448e
24 changed files with 339 additions and 153 deletions

1
.gitattributes vendored

@ -8,6 +8,7 @@ xlsx*.js text eol=lf
docbits/* linguist-documentation
dist/* linguist-generated=true binary
*.mjs linguist-generated=true binary
xlsx.js linguist-generated=true binary
xlsxworker.js linguist-generated=true binary
tests/core.js linguist-generated=true binary

@ -4,10 +4,21 @@ 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.17.2
* Browser and Node optional ESM support
* DSV correct handling of bare quotes (h/t @bgamrat)
## v0.17.1
* `XLSB` writer uses short cell form when viable
## 0.17.0:
* mini build includes ODS parse/write support
* DBF explicitly cap worksheet to 1<<20 rows
* XLS throw errors on truncated records
## v0.16.2
* Disabled `PRN` parsing by default (better support for CSV without delimeters)

@ -1 +1 @@
XLSX.version = '0.17.1';
XLSX.version = '0.17.2';

4
dist/jszip.js generated vendored

@ -329,9 +329,9 @@ DataReader.prototype = {
// see implementations
},
/**
* Find the last occurence of a zip signature (4 bytes).
* Find the last occurrence of a zip signature (4 bytes).
* @param {string} sig the signature to find.
* @return {number} the index of the last occurence, -1 if not found.
* @return {number} the index of the last occurrence, -1 if not found.
*/
lastIndexOfSignature: function(sig) {
// see implementations

32
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

54
dist/xlsx.extendscript.js generated vendored

@ -486,9 +486,9 @@ DataReader.prototype = {
// see implementations
},
/**
* Find the last occurence of a zip signature (4 bytes).
* Find the last occurrence of a zip signature (4 bytes).
* @param {string} sig the signature to find.
* @return {number} the index of the last occurence, -1 if not found.
* @return {number} the index of the last occurrence, -1 if not found.
*/
lastIndexOfSignature: function(sig) {
// see implementations
@ -9161,7 +9161,7 @@ module.exports = ZStream;
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -12016,7 +12016,8 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
/* TODO: stress test */
function fuzzynum(s) {
var v = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -15962,6 +15963,20 @@ function parse_ColInfo(blob, length, opts) {
if(opts.biff >= 5 || !opts.biff) o.level = (flags >> 8) & 0x7;
return o;
}
function write_ColInfo(col, idx) {
var o = new_buf(12);
o.write_shift(2, idx);
o.write_shift(2, idx);
o.write_shift(2, col.width * 256);
o.write_shift(2, 0);
var f = 0;
if(col.hidden) f |= 1;
o.write_shift(1, f);
f = col.level || 0;
o.write_shift(1, f);
o.write_shift(2, 0);
return o;
}
/* [MS-XLS] 2.4.257 */
function parse_Setup(blob, length) {
@ -16940,7 +16955,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -16972,13 +16987,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -18480,7 +18495,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -19592,7 +19607,7 @@ function parse_comments_xml(data, opts) {
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
comment.r = rt.r;
if(rt.r == "<t></t>") rt.t = rt.h = "";
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
@ -20702,7 +20717,7 @@ ixti = f[1][1]; r = f[1][2];
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else {
var ixtidata = get_ixti_raw(supbooks, bookidx, opts).split(";;");
var ixtidata = (get_ixti_raw(supbooks, bookidx, opts)||"").split(";;");
if(ixtidata[nameidx - 1]) o = ixtidata[nameidx - 1]; // TODO: confirm this is correct
else o += "SH33TJSERRX";
}
@ -22373,9 +22388,9 @@ function safe_format(p, fmtid, fillid, opts, themes, styles) {
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -24799,7 +24814,6 @@ function write_BrtFileVersion(data, o) {
write_XLWideString(XLSX.version, o);
write_XLWideString(XLSX.version, o);
write_XLWideString("7262", o);
o.length = o.l;
return o.length > o.l ? o.slice(0, o.l) : o;
}
@ -28589,6 +28603,16 @@ function write_ws_biff8_hlinks(ba, ws) {
delete ws['!links'];
}
function write_ws_cols_biff8(ba, cols, ws) {
if(!cols) return;
var cnt = 0;
cols.forEach(function(col, idx) {
if(++cnt <= 256 && col) {
write_biff_rec(ba, "ColInfo", write_ColInfo(col_obj_w(idx, col), idx));
}
});
}
function write_ws_biff8_cell(ba, cell, R, C, opts) {
var os = 16 + get_cell_style(opts.cellXfs, cell, opts);
if(cell.v == null && !cell.bf) {
@ -28652,6 +28676,8 @@ function write_ws_biff8(idx, opts, wb) {
write_biff_rec(ba, "HCenter", writebool(false));
write_biff_rec(ba, "VCenter", writebool(false));
/* ... */
if(b8) write_ws_cols_biff8(ba, ws["!cols"], ws);
/* ... */
write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
/* ... */
@ -29618,7 +29644,7 @@ var write_content_ods = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

28
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

50
dist/xlsx.js generated vendored

@ -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.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -2859,7 +2859,8 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
/* TODO: stress test */
function fuzzynum(s) {
var v = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -6805,6 +6806,20 @@ function parse_ColInfo(blob, length, opts) {
if(opts.biff >= 5 || !opts.biff) o.level = (flags >> 8) & 0x7;
return o;
}
function write_ColInfo(col, idx) {
var o = new_buf(12);
o.write_shift(2, idx);
o.write_shift(2, idx);
o.write_shift(2, col.width * 256);
o.write_shift(2, 0);
var f = 0;
if(col.hidden) f |= 1;
o.write_shift(1, f);
f = col.level || 0;
o.write_shift(1, f);
o.write_shift(2, 0);
return o;
}
/* [MS-XLS] 2.4.257 */
function parse_Setup(blob, length) {
@ -7783,7 +7798,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -7815,13 +7830,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -9323,7 +9338,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -10435,7 +10450,7 @@ function parse_comments_xml(data, opts) {
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
comment.r = rt.r;
if(rt.r == "<t></t>") rt.t = rt.h = "";
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
@ -11545,7 +11560,7 @@ ixti = f[1][1]; r = f[1][2];
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else {
var ixtidata = get_ixti_raw(supbooks, bookidx, opts).split(";;");
var ixtidata = (get_ixti_raw(supbooks, bookidx, opts)||"").split(";;");
if(ixtidata[nameidx - 1]) o = ixtidata[nameidx - 1]; // TODO: confirm this is correct
else o += "SH33TJSERRX";
}
@ -13216,9 +13231,9 @@ function safe_format(p, fmtid, fillid, opts, themes, styles) {
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -15642,7 +15657,6 @@ function write_BrtFileVersion(data, o) {
write_XLWideString(XLSX.version, o);
write_XLWideString(XLSX.version, o);
write_XLWideString("7262", o);
o.length = o.l;
return o.length > o.l ? o.slice(0, o.l) : o;
}
@ -19432,6 +19446,16 @@ function write_ws_biff8_hlinks(ba, ws) {
delete ws['!links'];
}
function write_ws_cols_biff8(ba, cols, ws) {
if(!cols) return;
var cnt = 0;
cols.forEach(function(col, idx) {
if(++cnt <= 256 && col) {
write_biff_rec(ba, "ColInfo", write_ColInfo(col_obj_w(idx, col), idx));
}
});
}
function write_ws_biff8_cell(ba, cell, R, C, opts) {
var os = 16 + get_cell_style(opts.cellXfs, cell, opts);
if(cell.v == null && !cell.bf) {
@ -19495,6 +19519,8 @@ function write_ws_biff8(idx, opts, wb) {
write_biff_rec(ba, "HCenter", writebool(false));
write_biff_rec(ba, "VCenter", writebool(false));
/* ... */
if(b8) write_ws_cols_biff8(ba, ws["!cols"], ws);
/* ... */
write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
/* ... */
@ -20461,7 +20487,7 @@ var write_content_ods = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

28
dist/xlsx.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map generated vendored

File diff suppressed because one or more lines are too long

16
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

@ -64,6 +64,7 @@ function zip_add_file(zip, path, content) {
else zip.file(path, content);
}
var jszip;
function zip_new() {
return CFB.utils.cfb_new();

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.17.1",
"version": "0.17.2",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [
@ -21,9 +21,8 @@
"xlsx": "./bin/xlsx.njs"
},
"main": "xlsx.js",
"module": "xlsx.mjs",
"unpkg": "dist/xlsx.min.js",
"jsdelivr": "dist/xlsx.min.js",
"unpkg": "dist/xlsx.full.min.js",
"jsdelivr": "dist/xlsx.full.min.js",
"types": "types/index.d.ts",
"browser": {
"buffer": false,

61
tests/esm.html Normal file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>JS-XLSX Core Test Runner</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="mocha.css" />
<link rel="icon" type="image/png" href="//oss.sheetjs.com/assets/img/logo.png" />
<style>
#t { font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 0px 60px; font-weight: bold; }
#tt{ font: 16px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 0px 60px; }
th { font: 16px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 0px 60px; font-weight: bold; text-align: left; }
</style>
</head>
<body>
<h1 id="t"><a href="http://sheetjs.com">JS-XLSX Browser-based Parsing Tests</a></h1>
<table id="tt">
<tr>
<th>File Formats</th>
<td><a href="http://github.com/SheetJS/js-xlsx">Library Source</a></td>
<td><a href="http://SheetJS.github.io/js-xls">Interactive Demo</a></td>
<td><a href="http://npm.im/xlsx">"xlsx" on npm</a></td>
<td><a href="https://travis-ci.org/SheetJS/js-xlsx">node CI status</a></td>
</tr>
<tr><td colspan="5">Tests compiled from <a href="http://github.com/SheetJS/test_files">test_files repo</a> and are located at /test_files<br /></td></tr>
</table>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script src="shim.js"></script>
<script src="base64.js"></script>
<script src="fs_.js"></script>
<script src="fixtures.js"></script>
<script src="cpexcel.js"></script>
<script type="module">
import * as XLSX from './xlsx.mjs';
if(typeof XLSX !== "undefined") globalThis.XLSX = XLSX;
else if(typeof globalThis !== "undefined" && !globalThis.XLSX) globalThis.XLSX = XLSX;
</script>
<div id="mocha"></div>
<script src="mocha.js"></script>
<script>
window.initMochaPhantomJS && window.initMochaPhantomJS();
mocha.setup({ui:'bdd', timeout:15000});
</script>
<script src="core.js" type="module"></script>
<script type="module">
if(typeof mochaSaucePlease !== "undefined") mochaSaucePlease();
else if(window.mochaPhantomJS) mochaPhantomJS.run();
else typeof mocha_sauce !== 'undefined' ? mocha_sauce() : mocha.run();
</script>
</body>
</html>

1
tests/xlsx.mjs generated Symbolic link

@ -0,0 +1 @@
../xlsx.mjs

22
xlsx.esm.mjs generated

@ -3,7 +3,7 @@
/*exported XLSX */
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
XLSX.version = '0.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -2915,7 +2915,8 @@ function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length
/* TODO: stress test */
function fuzzynum(s/*:string*/)/*:number*/ {
var v/*:number*/ = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -3008,6 +3009,7 @@ function zip_add_file(zip, path, content) {
else zip.file(path, content);
}
var jszip;
function zip_new() {
return CFB.utils.cfb_new();
@ -7817,7 +7819,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re/*:?RegExp*/ = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -7849,13 +7851,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -9358,7 +9360,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -11583,7 +11585,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else {
var ixtidata = get_ixti_raw(supbooks, bookidx, opts).split(";;");
var ixtidata = (get_ixti_raw(supbooks, bookidx, opts)||"").split(";;");
if(ixtidata[nameidx - 1]) o = ixtidata[nameidx - 1]; // TODO: confirm this is correct
else o += "SH33TJSERRX";
}
@ -13254,9 +13256,9 @@ function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, the
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -20526,7 +20528,7 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

@ -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.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -2939,7 +2939,8 @@ function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length
/* TODO: stress test */
function fuzzynum(s/*:string*/)/*:number*/ {
var v/*:number*/ = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -6902,6 +6903,20 @@ function parse_ColInfo(blob, length, opts) {
if(opts.biff >= 5 || !opts.biff) o.level = (flags >> 8) & 0x7;
return o;
}
function write_ColInfo(col, idx) {
var o = new_buf(12);
o.write_shift(2, idx);
o.write_shift(2, idx);
o.write_shift(2, col.width * 256);
o.write_shift(2, 0);
var f = 0;
if(col.hidden) f |= 1;
o.write_shift(1, f);
f = col.level || 0;
o.write_shift(1, f);
o.write_shift(2, 0);
return o;
}
/* [MS-XLS] 2.4.257 */
function parse_Setup(blob, length) {
@ -7881,7 +7896,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re/*:?RegExp*/ = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -7913,13 +7928,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -9422,7 +9437,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -10536,7 +10551,7 @@ function parse_comments_xml(data/*:string*/, opts)/*:Array<RawComment>*/ {
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
comment.r = rt.r;
if(rt.r == "<t></t>") rt.t = rt.h = "";
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
@ -11647,7 +11662,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else {
var ixtidata = get_ixti_raw(supbooks, bookidx, opts).split(";;");
var ixtidata = (get_ixti_raw(supbooks, bookidx, opts)||"").split(";;");
if(ixtidata[nameidx - 1]) o = ixtidata[nameidx - 1]; // TODO: confirm this is correct
else o += "SH33TJSERRX";
}
@ -13318,9 +13333,9 @@ function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, the
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -15747,7 +15762,6 @@ function write_BrtFileVersion(data, o) {
write_XLWideString(XLSX.version, o);
write_XLWideString(XLSX.version, o);
write_XLWideString("7262", o);
o.length = o.l;
return o.length > o.l ? o.slice(0, o.l) : o;
}
@ -19550,6 +19564,16 @@ function write_ws_biff8_hlinks(ba/*:BufArray*/, ws) {
delete ws['!links'];
}
function write_ws_cols_biff8(ba, cols, ws) {
if(!cols) return;
var cnt = 0;
cols.forEach(function(col, idx) {
if(++cnt <= 256 && col) {
write_biff_rec(ba, "ColInfo", write_ColInfo(col_obj_w(idx, col), idx));
}
});
}
function write_ws_biff8_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:number*/, opts) {
var os = 16 + get_cell_style(opts.cellXfs, cell, opts);
if(cell.v == null && !cell.bf) {
@ -19613,6 +19637,8 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) {
write_biff_rec(ba, "HCenter", writebool(false));
write_biff_rec(ba, "VCenter", writebool(false));
/* ... */
if(b8) write_ws_cols_biff8(ba, ws["!cols"], ws);
/* ... */
write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
/* ... */
@ -20579,7 +20605,7 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

50
xlsx.js generated

@ -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.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -2859,7 +2859,8 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
/* TODO: stress test */
function fuzzynum(s) {
var v = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -6805,6 +6806,20 @@ function parse_ColInfo(blob, length, opts) {
if(opts.biff >= 5 || !opts.biff) o.level = (flags >> 8) & 0x7;
return o;
}
function write_ColInfo(col, idx) {
var o = new_buf(12);
o.write_shift(2, idx);
o.write_shift(2, idx);
o.write_shift(2, col.width * 256);
o.write_shift(2, 0);
var f = 0;
if(col.hidden) f |= 1;
o.write_shift(1, f);
f = col.level || 0;
o.write_shift(1, f);
o.write_shift(2, 0);
return o;
}
/* [MS-XLS] 2.4.257 */
function parse_Setup(blob, length) {
@ -7783,7 +7798,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -7815,13 +7830,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -9323,7 +9338,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -10435,7 +10450,7 @@ function parse_comments_xml(data, opts) {
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
comment.r = rt.r;
if(rt.r == "<t></t>") rt.t = rt.h = "";
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
@ -11545,7 +11560,7 @@ ixti = f[1][1]; r = f[1][2];
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else {
var ixtidata = get_ixti_raw(supbooks, bookidx, opts).split(";;");
var ixtidata = (get_ixti_raw(supbooks, bookidx, opts)||"").split(";;");
if(ixtidata[nameidx - 1]) o = ixtidata[nameidx - 1]; // TODO: confirm this is correct
else o += "SH33TJSERRX";
}
@ -13216,9 +13231,9 @@ function safe_format(p, fmtid, fillid, opts, themes, styles) {
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -15642,7 +15657,6 @@ function write_BrtFileVersion(data, o) {
write_XLWideString(XLSX.version, o);
write_XLWideString(XLSX.version, o);
write_XLWideString("7262", o);
o.length = o.l;
return o.length > o.l ? o.slice(0, o.l) : o;
}
@ -19432,6 +19446,16 @@ function write_ws_biff8_hlinks(ba, ws) {
delete ws['!links'];
}
function write_ws_cols_biff8(ba, cols, ws) {
if(!cols) return;
var cnt = 0;
cols.forEach(function(col, idx) {
if(++cnt <= 256 && col) {
write_biff_rec(ba, "ColInfo", write_ColInfo(col_obj_w(idx, col), idx));
}
});
}
function write_ws_biff8_cell(ba, cell, R, C, opts) {
var os = 16 + get_cell_style(opts.cellXfs, cell, opts);
if(cell.v == null && !cell.bf) {
@ -19495,6 +19519,8 @@ function write_ws_biff8(idx, opts, wb) {
write_biff_rec(ba, "HCenter", writebool(false));
write_biff_rec(ba, "VCenter", writebool(false));
/* ... */
if(b8) write_ws_cols_biff8(ba, ws["!cols"], ws);
/* ... */
write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
/* ... */
@ -20461,7 +20487,7 @@ var write_content_ods = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

@ -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.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -2917,7 +2917,8 @@ function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length
/* TODO: stress test */
function fuzzynum(s/*:string*/)/*:number*/ {
var v/*:number*/ = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -3010,6 +3011,7 @@ function zip_add_file(zip, path, content) {
else zip.file(path, content);
}
var jszip;
function zip_new() {
return CFB.utils.cfb_new();
@ -5642,7 +5644,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re/*:?RegExp*/ = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -5674,13 +5676,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;
start = end+1;
start = end+1; startcc = str.charCodeAt(start);
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case 0x22: if(startcc === 0x22) instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
@ -6434,7 +6436,7 @@ function parse_cellXfs(t, styles, opts) {
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
if(xf.numFmtId > 0x188) {
if(styles.NumberFmt && xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
@ -7012,7 +7014,7 @@ function parse_comments_xml(data/*:string*/, opts)/*:Array<RawComment>*/ {
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
comment.r = rt.r;
if(rt.r == "<t></t>") rt.t = rt.h = "";
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
@ -7223,9 +7225,9 @@ function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, the
try {
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
if(p.t === 'z') return;
if(p.t === 'z' && !opts.cellStyles) return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
if(!opts || opts.cellText !== false) try {
if((!opts || opts.cellText !== false) && p.t !== 'z') try {
if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
@ -9336,7 +9338,7 @@ var write_content_ods/*:{(wb:any, opts:any):string}*/ = (function() {
return escapexml(text)
.replace(/ +/g, function($$){return '<text:s text:c="'+$$.length+'"/>';})
.replace(/\t/g, "<text:tab/>")
.replace(/\n/g, "<text:line-break/>")
.replace(/\n/g, "</text:p><text:p>")
.replace(/^ /, "<text:s/>").replace(/ $/, "<text:s/>");
};

@ -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.17.1';
XLSX.version = '0.17.2';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -2838,7 +2838,8 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
/* TODO: stress test */
function fuzzynum(s) {
var v = Number(s);
if(!isNaN(v)) return v;
if(isFinite(v)) return v;
if(!isNaN(v)) return NaN;
if(!/\d/.test(s)) return v;
var wt = 1;
var ss = s.replace(/([\d]),([\d])/g,"$1$2").replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";});
@ -2931,6 +2932,7 @@ function zip_add_file(zip, path, content) {
else zip.file(path, content);
}
var jszip;
function zip_new() {
return CFB.utils.cfb_new();
@ -5551,7 +5553,7 @@ var PRN = (function() {
}
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0, startcc=str.charCodeAt(0);
str = str.replace(/\r\n/mg, "\n");
var _re = o.dateNF != null ? dateNF_regex(o.dateNF) : null;
function finish_cell() {
@ -5583,13 +5585,13 @@ var PRN = (function() {
if(cell.t == 'z'){}
else if(o.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = cell; }
else ws[encode_cell({c:C,r:R})] = cell;