updating to 0.11.19

This commit is contained in:
SheetJS 2018-02-03 15:43:07 -05:00
parent b208f2ed9c
commit c032503f93
6 changed files with 135 additions and 73 deletions

View File

@ -40,8 +40,7 @@ Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" c
<div id="htmlout"></div>
<br />
<script src="https://unpkg.com/canvas-datagrid/dist/canvas-datagrid.js"></script>
<script type="text/javascript" src="https://rawgit.com/eligrey/Blob.js/master/Blob.js"></script>
<script type="text/javascript" src="https://rawgit.com/eligrey/FileSaver.js/master/FileSaver.js"></script>
<script src="shim.js"></script>
<script src="xlsx.full.min.js"></script>
<script>
/*jshint browser:true */
@ -151,11 +150,7 @@ var export_xlsx = (function() {
XLSX.utils.book_append_sheet(new_wb, new_ws, 'SheetJS');
/* write file and trigger a download */
var wbout = XLSX.write(new_wb, {bookType:'xlsx', bookSST:true, type:'array'});
var fname = 'sheetjs.xlsx';
try {
saveAs(new Blob([wbout],{type:"application/octet-stream"}), fname);
} catch(e) { if(typeof console != 'undefined') console.log(e, wbout); }
XLSX.writeFile(new_wb, 'sheetjs.xlsx', {bookSST:true});
};
})();
</script>

27
shim.js
View File

@ -341,3 +341,30 @@ if(typeof Uint8Array !== 'undefined' && !Uint8Array.prototype.slice) Uint8Array.
while(start <= --end) out[end - start] = this[end];
return out;
};
// VBScript + ActiveX fallback for IE5+
var IE_SaveFile = (function() { try {
if(typeof IE_SaveFile_Impl == "undefined") document.write([
'<script type="text/vbscript" language="vbscript">',
'IE_GetProfileAndPath_Key = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\"',
'Function IE_GetProfileAndPath(key): Set wshell = CreateObject("WScript.Shell"): IE_GetProfileAndPath = wshell.RegRead(IE_GetProfileAndPath_Key & key): IE_GetProfileAndPath = wshell.ExpandEnvironmentStrings("%USERPROFILE%") & "!" & IE_GetProfileAndPath: End Function',
'Function IE_SaveFile_Impl(FileName, payload): Dim data, plen, i, bit: data = CStr(payload): plen = Len(data): Set fso = CreateObject("Scripting.FileSystemObject"): fso.CreateTextFile FileName, True: Set f = fso.GetFile(FileName): Set stream = f.OpenAsTextStream(2, 0): For i = 1 To plen Step 3: bit = Mid(data, i, 2): stream.write Chr(CLng("&h" & bit)): Next: stream.Close: IE_SaveFile_Impl = True: End Function',
'|/script>'.replace("|","<")
].join("\r\n"));
if(typeof IE_SaveFile_Impl == "undefined") return void 0;
var IE_GetPath = (function() {
var DDP1 = "";
try { DDP1 = IE_GetProfileAndPath("{374DE290-123F-4565-9164-39C4925E467B}"); } catch(e) { try { DDP1 = IE_GetProfileAndPath("Personal"); } catch(e) { try { DDP1 = IE_GetProfileAndPath("Desktop"); } catch(e) { throw e; }}}
var o = DDP1.split("!");
DDP = o[1].replace("%USERPROFILE%", o[0]);
return function(path) { return DDP + "\\" + path; };
})();
function fix_data(data) {
var out = [];
var T = typeof data == "string";
for(var i = 0; i < data.length; ++i) out.push(("00"+(T ? data.charCodeAt(i) : data[i]).toString(16)).slice(-2));
var o = out.join("|");
return o;
}
return function(data, filename) { return IE_SaveFile_Impl(IE_GetPath(filename), fix_data(data)); };
} catch(e) { return void 0; }})();

View File

@ -1,7 +1,9 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*jshint mocha:true */
/* eslint-env mocha */
/*global process, document, require */
/*global ArrayBuffer, Uint8Array */
/*::
declare type EmptyFunc = (() => void) | null;
declare type DescribeIt = { (desc:string, test:EmptyFunc):void; skip(desc:string, test:EmptyFunc):void; };
@ -17,6 +19,7 @@ describe('source',function(){it('should load',function(){X=require(modp);});});
var DIF_XL = true;
var browser = typeof document !== 'undefined';
// $FlowIgnore
if(!browser) try { require('./shim'); } catch(e) { }
var opts = ({cellNF: true}/*:any*/);
@ -189,7 +192,6 @@ var MCPaths = pathit("mc", ["xlsx", "xlsb", "xls", "xml", "ods"]);
var CSSPaths = pathit("css", ["xlsx", "xlsb", "xls", "xml"]);
var NFPaths = pathit("nf", ["xlsx", "xlsb", "xls", "xml"]);
var DTPaths = pathit("dt", ["xlsx", "xlsb", "xls", "xml"]);
var NFPaths = pathit("nf", ["xlsx", "xlsb", "xls", "xml"]);
var HLPaths = pathit("hl", ["xlsx", "xlsb", "xls", "xml"]);
var ILPaths = pathit("il", ["xlsx", "xlsb", "xls", "xml", "ods", "xls5"]);
var OLPaths = pathit("ol", ["xlsx", "xlsb", "xls", "ods", "xls5"]);
@ -317,12 +319,11 @@ var wbtable = {};
wbtable[dir + x] = wb;
parsetest(x, wb, true);
});
fullex.forEach(function(ext, idx) {
fullex.forEach(function(ext) {
it(x + ' [' + ext + ']', function(){
var wb = wbtable[dir + x];
if(!wb) wb = X.readFile(dir + x, opts);
wb = X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF, cellNF: true});
parsetest(x, wb, ext.replace(/\./,"") !== "xlsb", ext);
});
});
@ -470,7 +471,7 @@ describe('parse options', function() {
[paths.cssxlsx /*, paths.cssxlsb, paths.cssxls, paths.cssxml*/].forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type:TYPE, cellStyles:true});
var found = false;
each_sheet(wb, function(ws, i) { each_cell(ws, function(cell) {
each_sheet(wb, function(ws/*::, i*/) { /*:: void i; */each_cell(ws, function(cell) {
if(typeof cell.s !== 'undefined') return (found = true);
}); });
assert(found);
@ -479,7 +480,7 @@ describe('parse options', function() {
it('should not generate cell dates by default', function() {
DTPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type:TYPE});
each_sheet(wb, function(ws, i) { each_cell(ws, function(cell) {
each_sheet(wb, function(ws/*::, i*/) { /*:: void i; */each_cell(ws, function(cell) {
assert(cell.t !== 'd');
}); });
});
@ -488,7 +489,7 @@ describe('parse options', function() {
DTPaths.forEach(function(p) {
var wb = X.read(fs.readFileSync(p), {type:TYPE, cellDates: true, WTF:1});
var found = false;
each_sheet(wb, function(ws, i) { each_cell(ws, function(cell) {
each_sheet(wb, function(ws/*::, i*/) { /*:: void i; */each_cell(ws, function(cell) {
if(cell.t === 'd') return (found = true);
}); });
assert(found);
@ -910,7 +911,7 @@ describe('parse features', function() {
var wbs = [], wbs_no_slk = [];
var bef = (function() {
X = require(modp);
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(CWPaths[0]), {type:TYPE, cellStyles:true}); });
wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); });
wbs_no_slk = wbs.slice(0, 5);
});
if(typeof before != 'undefined') before(bef);
@ -1171,6 +1172,7 @@ describe('parse features', function() {
'A3:A10', 'B3:B10', 'E1:E10', 'F6:F8', /* cols */
'H1:J4', 'H10' /* blocks */
];
/*eslint-disable */
var exp/*:Array<any>*/ = [
{ patternType: 'darkHorizontal',
fgColor: { theme: 9, raw_rgb: 'F79646' },
@ -1197,6 +1199,7 @@ describe('parse features', function() {
fgColor: { theme: 3, raw_rgb: 'EEECE1' },
bgColor: { theme: 7, raw_rgb: '8064A2' } }
];
/*eslint-enable */
ranges.forEach(function(rng) {
it('XLS | ' + rng,function(){cmparr(rn2(rng).map(function(x){ return get_cell(wsxls,x).s; }));});
it('XLSX | ' + rng,function(){cmparr(rn2(rng).map(function(x){ return get_cell(wsxlsx,x).s; }));});
@ -1698,7 +1701,7 @@ describe('json output', function() {
});
it('should preserve values when column header is missing', function() {
/*jshint elision:true */
var _data = [[,"a","b",,"c"], [1,2,3,,5],[,3,4,5,6]];
var _data = [[,"a","b",,"c"], [1,2,3,,5],[,3,4,5,6]]; // eslint-disable-line no-sparse-arrays
/*jshint elision:false */
var _ws = X.utils.aoa_to_sheet(_data);
var json1 = X.utils.sheet_to_json(_ws, { raw: true });
@ -1720,7 +1723,7 @@ var plaintext_val = [
["B3", 's', " ", " "],
["A3"]
];
function plaintext_test(wb, raw, t) {
function plaintext_test(wb, raw) {
var sheet = wb.Sheets[wb.SheetNames[0]];
plaintext_val.forEach(function(x) {
var cell = get_cell(sheet, x[0]);
@ -1790,8 +1793,8 @@ describe('CSV', function() {
assert.equal(cell.v.getMonth(), 2);
assert.equal(cell.w, "2/3/14");
});
it('should interpret values by default', function() { plaintext_test(X.read(csv_bstr, {type:"binary"}), false, false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(csv_str, {type:"string", raw:true}), true, false); });
it('should interpret values by default', function() { plaintext_test(X.read(csv_bstr, {type:"binary"}), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(csv_str, {type:"string", raw:true}), true); });
it('should handle formulae', function() {
var bb = '=,=1+1,="100"';
var sheet = X.read(bb, {type:"binary"}).Sheets.Sheet1;
@ -1920,9 +1923,9 @@ function get_dom_element(html) {
describe('HTML', function() {
describe('input string', function(){
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"binary"}), false, false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"binary", raw:true}), true, false); });
it('should handle "string" type', function() { plaintext_test(X.read(html_str, {type:"string"}), false, false); });
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"binary"}), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"binary", raw:true}), true); });
it('should handle "string" type', function() { plaintext_test(X.read(html_str, {type:"string"}), false); });
it('should handle newlines correctly', function() {
var table = "<table><tr><td>foo<br/>bar</td><td>baz</td></tr></table>";
var wb = X.read(table, {type:"string"});
@ -1930,8 +1933,8 @@ describe('HTML', function() {
});
});
(domtest ? describe : describe.skip)('input DOM', function() {
it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false, true); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str), {raw:true}), true, true); });
it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str), {raw:true}), true); });
it('should handle newlines correctly', function() {
var table = get_dom_element("<table><tr><td>foo<br/>bar</td><td>baz</td></tr></table>");
var ws = X.utils.table_to_sheet(table);
@ -2029,14 +2032,14 @@ describe('corner cases', function() {
});
it('SSF', function() {
X.SSF.format("General", "dafuq");
assert.throws(function(x) { return X.SSF.format("General", {sheet:"js"});});
assert.throws(function() { return X.SSF.format("General", {sheet:"js"});});
X.SSF.format("b e ddd hh AM/PM", 41722.4097222222);
X.SSF.format("b ddd hh m", 41722.4097222222);
["hhh","hhh A/P","hhmmm","sss","[hhh]","G eneral"].forEach(function(f) {
assert.throws(function(x) { return X.SSF.format(f, 12345.6789);});
assert.throws(function() { return X.SSF.format(f, 12345.6789);});
});
["[m]","[s]"].forEach(function(f) {
assert.doesNotThrow(function(x) { return X.SSF.format(f, 12345.6789);});
assert.doesNotThrow(function() { return X.SSF.format(f, 12345.6789);});
});
});
if(typeof JSON !== 'undefined') it('SSF oddities', function() {

26
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

30
xlsx.full.min.js vendored

File diff suppressed because one or more lines are too long

75
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(XLSX){
XLSX.version = '0.11.18';
XLSX.version = '0.11.19';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -140,11 +140,16 @@ function s2ab(s) {
return buf;
}
function arr2str(data) {
function a2s(data) {
if(Array.isArray(data)) return data.map(_chr).join("");
var o = []; for(var i = 0; i < data.length; ++i) o[i] = _chr(data[i]); return o.join("");
}
function a2u(data) {
if(typeof Uint8Array === 'undefined') throw new Error("Unsupported");
return new Uint8Array(data);
}
function ab2a(data) {
if(typeof ArrayBuffer == 'undefined') throw new Error("Unsupported");
if(data instanceof ArrayBuffer) return ab2a(new Uint8Array(data));
@ -1782,6 +1787,39 @@ return exports;
})();
if(typeof require !== 'undefined' && typeof module !== 'undefined' && typeof DO_NOT_EXPORT_CFB === 'undefined') { module.exports = CFB; }
var _fs;
if(typeof require !== 'undefined') try { _fs = require('fs'); } catch(e) {}
/* normalize data for blob ctor */
function blobify(data) {
if(typeof data === "string") return s2ab(data);
if(Array.isArray(data)) return a2u(data);
return data;
}
/* write or download file */
function write_dl(fname, payload, enc) {
/*global IE_SaveFile, Blob, navigator, saveAs, URL, document */
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);
if(typeof Blob !== 'undefined') {
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
var a = document.createElement("a");
if(a.download != null) {
var url = URL.createObjectURL(blob);
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
document.body.removeChild(a);
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
return url;
}
}
}
throw new Error("cannot initiate download");
}
function keys(o) { return Object.keys(o); }
function evert_key(obj, key) {
@ -1973,13 +2011,12 @@ function getzipstr(zip, file, safe) {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
var _fs, jszip;
var jszip;
/*global JSZip:true */
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
if(typeof exports !== 'undefined') {
if(typeof module !== 'undefined' && module.exports) {
if(typeof jszip === 'undefined') jszip = require('./jszip.js');
try { _fs = require('fs'); } catch(e) { }
}
}
@ -13286,6 +13323,7 @@ function check_wb_names(N) {
}
function check_wb(wb) {
if(!wb || !wb.SheetNames || !wb.Sheets) throw new Error("Invalid Workbook");
if(!wb.SheetNames.length) throw new Error("Workbook is empty");
check_wb_names(wb.SheetNames);
/* TODO: validate workbook */
}
@ -14723,7 +14761,7 @@ function parse_xlml(data, opts) {
switch(opts.type||"base64") {
case "base64": return parse_xlml_xml(Base64.decode(data), opts);
case "binary": case "buffer": case "file": return parse_xlml_xml(data, opts);
case "array": return parse_xlml_xml(arr2str(data), opts);
case "array": return parse_xlml_xml(a2s(data), opts);
}
}
@ -17536,9 +17574,9 @@ var HTML_ = (function() {
var preamble = "<tr>";
return preamble + oo.join("") + "</tr>";
}
function make_html_preamble() {
function make_html_preamble(ws, R, o) {
var out = [];
return out.join("") + '<table>';
return out.join("") + '<table' + (o && o.id ? ' id="' + o.id + '"' : "") + '>';
}
var _BEGIN = '<html><head><meta charset="utf-8"/><title>SheetJS Table Export</title></head><body>';
var _END = '</body></html>';
@ -18899,7 +18937,6 @@ function readSync(data, opts) {
case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o);
}
if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o);
if(0x20>n[0]||n[0]>0x7F) throw new Error("Unsupported file " + n.join("|"));
return read_prn(data, d, o, str);
}
@ -18915,12 +18952,12 @@ function write_zip_type(wb, opts) {
switch(o.type) {
case "base64": oopts.type = "base64"; break;
case "binary": oopts.type = "string"; break;
case "string": throw new Error("'string' output type invalid for '" + o.bookType + ' files');
case "string": throw new Error("'string' output type invalid for '" + o.bookType + "' files");
case "buffer":
case "file": oopts.type = "nodebuffer"; break;
case "file": oopts.type = has_buf ? "nodebuffer" : "string"; break;
default: throw new Error("Unrecognized type " + o.type);
}
if(o.type === "file") return _fs.writeFileSync(o.file, z.generate(oopts));
if(o.type === "file") return write_dl(o.file, z.generate(oopts));
var out = z.generate(oopts);
// $FlowIgnore
return o.type == "string" ? utf8read(out) : out;
@ -18932,8 +18969,8 @@ function write_cfb_type(wb, opts) {
switch(o.type) {
case "base64": case "binary": break;
case "buffer": case "array": o.type = ""; break;
case "file": return _fs.writeFileSync(o.file, CFB.write(cfb, {type:'buffer'}));
case "string": throw new Error("'string' output type invalid for '" + o.bookType + ' files');
case "file": return write_dl(o.file, CFB.write(cfb, {type:has_buf ? 'buffer' : ""}));
case "string": throw new Error("'string' output type invalid for '" + o.bookType + "' files");
default: throw new Error("Unrecognized type " + o.type);
}
return CFB.write(cfb, o);
@ -18946,7 +18983,7 @@ function write_string_type(out, opts, bom) {
case "base64": return Base64.encode(utf8write(o));
case "binary": return utf8write(o);
case "string": return out;
case "file": return _fs.writeFileSync(opts.file, o, 'utf8');
case "file": return write_dl(opts.file, o, 'utf8');
case "buffer": {
if(has_buf) return new Buffer(o, 'utf8');
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
@ -18960,7 +18997,7 @@ function write_stxt_type(out, opts) {
case "base64": return Base64.encode(out);
case "binary": return out;
case "string": return out; /* override in sheet_to_txt */
case "file": return _fs.writeFileSync(opts.file, out, 'binary');
case "file": return write_dl(opts.file, out, 'binary');
case "buffer": {
if(has_buf) return new Buffer(out, 'binary');
else return out.split("").map(function(c) { return c.charCodeAt(0); });
@ -18979,7 +19016,7 @@ function write_binary_type(out, opts) {
// $FlowIgnore
for(var i = 0; i < out.length; ++i) bstr += String.fromCharCode(out[i]);
return opts.type == 'base64' ? Base64.encode(bstr) : opts.type == 'string' ? utf8read(bstr) : bstr;
case "file": return _fs.writeFileSync(opts.file, out);
case "file": return write_dl(opts.file, out);
case "buffer": return out;
default: throw new Error("Unrecognized type " + opts.type);
}
@ -19182,7 +19219,7 @@ function sheet_to_txt(sheet, opts) {
var s = sheet_to_csv(sheet, opts);
if(typeof cptable == 'undefined' || opts.type == 'string') return s;
var o = cptable.utils.encode(1200, s, 'str');
return "\xff\xfe" + o;
return String.fromCharCode(255) + String.fromCharCode(254) + o;
}
function sheet_to_formulae(sheet) {