updating to 0.7.7

This commit is contained in:
SheetJS 2014-06-29 14:35:10 -04:00
parent 28f7b4c718
commit b8e6536323
7 changed files with 1479 additions and 1017 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
test_files/

@ -3,7 +3,7 @@
<!-- vim: set ts=2: -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JS-XLSX Live Demo</title>
<style>
#drop{
@ -22,31 +22,70 @@
</head>
<body>
<b>JS-XLSX (XLSX/XLSB/XLSM) Live Demo</b><br />
<a href="https://github.com/SheetJS/js-xlsx">Github Repo</a><br />
<a href="https://github.com/SheetJS/js-xlsx/issues">Issues? Something look weird? Click here and report an issue</a><br />
<input type="radio" name="format" value="csv" checked> CSV<br>
Output Format:
<select name="format">
<option value="csv" selected> CSV</option>
<option value="json"> JSON</option>
<option value="form"> FORMULAE</option>
</select><br />
<!--<input type="radio" name="format" value="csv" checked> CSV<br>
<input type="radio" name="format" value="json"> JSON<br>
<input type="radio" name="format" value="form"> FORMULAE<br>
<input type="radio" name="format" value="form"> FORMULAE<br> -->
<div id="drop">Drop an XLSX or XLSM or XLSB file here to see sheet data.</div>
<textarea id="b64data">... or paste a base64-encoding here</textarea>
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/>
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
Advanced Demo Options: <br />
Use Web Workers: (when available) <input type="checkbox" name="useworker" checked><br />
Use Transferrables: (when available) <input type="checkbox" name="xferable" checked><br />
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked><br />
<pre id="out"></pre>
<br />
<!-- uncomment the next line here and in xlsxworker.js for encoding support -->
<!--<script src="dist/cpexcel.js"></script>-->
<script src="shim.js"></script>
<script src="jszip.js"></script>
<script src="xlsx.js"></script>
<script>
var rABS = typeof FileReader !== "undefined" && typeof FileReader.prototype !== "undefined" && typeof FileReader.prototype.readAsBinaryString !== "undefined";
if(!rABS) {
document.getElementsByName("userabs")[0].disabled = true;
document.getElementsByName("userabs")[0].checked = false;
}
var use_worker = typeof Worker !== 'undefined';
if(!use_worker) {
document.getElementsByName("useworker")[0].disabled = true;
document.getElementsByName("useworker")[0].checked = false;
}
var transferable = true;
if(!transferable) {
document.getElementsByName("xferable")[0].disabled = true;
document.getElementsByName("xferable")[0].checked = false;
}
function fixdata(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l)
o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(o.length)));
for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(l*w)));
return o;
}
function xlsxworker(data, cb) {
function ab2str(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint16Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint16Array(data.slice(l*w)));
return o;
}
function s2ab(s) {
var b = new ArrayBuffer(s.length*2), v = new Uint16Array(b);
for (var i=0; i != s.length; ++i) v[i] = s.charCodeAt(i);
return [v, b];
}
function xlsxworker_noxfer(data, cb) {
var worker = new Worker('./xlsxworker.js');
worker.onmessage = function(e) {
switch(e.data.t) {
@ -59,10 +98,33 @@ function xlsxworker(data, cb) {
worker.postMessage({d:arr,b:rABS});
}
function xlsxworker_xfer(data, cb) {
var worker = new Worker(rABS ? './xlsxworker2.js' : './xlsxworker1.js');
worker.onmessage = function(e) {
switch(e.data.t) {
case 'ready': break;
case 'e': console.error(e.data.d); break;
default: xx=ab2str(e.data).replace(/\n/g,"\\n").replace(/\r/g,"\\r"); console.log("done"); cb(JSON.parse(xx)); break;
}
};
if(rABS) {
var val = s2ab(data);
worker.postMessage(val[1], [val[1]]);
} else {
worker.postMessage(data, [data]);
}
}
function xlsxworker(data, cb) {
transferable = document.getElementsByName("xferable")[0].checked;
if(transferable) xlsxworker_xfer(data, cb);
else xlsxworker_noxfer(data, cb);
}
function get_radio_value( radioName ) {
var radios = document.getElementsByName( radioName );
for( var i = 0; i < radios.length; i++ ) {
if( radios[i].checked ) {
if( radios[i].checked || radios.length === 1 ) {
return radios[i].value;
}
}
@ -133,15 +195,17 @@ var drop = document.getElementById('drop');
function handleDrop(e) {
e.stopPropagation();
e.preventDefault();
rABS = document.getElementsByName("userabs")[0].checked;
use_worker = document.getElementsByName("useworker")[0].checked;
var files = e.dataTransfer.files;
var i,f;
for (i = 0, f = files[i]; i != files.length; ++i) {
var reader = new FileReader();
var name = f.name;
reader.onload = function(e) {
if(typeof console !== 'undefined') console.log("onload", new Date());
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
var data = e.target.result;
if(typeof Worker !== 'undefined') {
if(use_worker) {
xlsxworker(data, process_wb);
} else {
var wb;

10
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

2327
xlsx.js

File diff suppressed because it is too large Load Diff

@ -1,12 +1,14 @@
/* xlsx.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
importScripts('xlsx.core.min.js');
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('jszip.js');
importScripts('xlsx.js');
postMessage({t:"ready"});
onmessage = function (oEvent) {
var v;
try {
//postMessage({t:'e', d:oEvent.data.b});
v = XLSX.read(oEvent.data.d, {type: oEvent.data.b ? 'binary': 'base64'});
} catch(e) { postMessage({t:"e",d:e.stack}); }
v = XLSX.read(oEvent.data.d, {type: oEvent.data.b ? 'binary' : 'base64'});
} catch(e) { postMessage({t:"e",d:e.stack||e}); }
postMessage({t:"xlsx", d:JSON.stringify(v)});
};

29
xlsxworker1.js Normal file

@ -0,0 +1,29 @@
/* xlsx.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('jszip.js');
importScripts('xlsx.js');
postMessage({t:"ready"});
function ab2str(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(l*w)));
return o;
}
function s2ab(s) {
var b = new ArrayBuffer(s.length*2), v = new Uint16Array(b);
for (var i=0; i != s.length; ++i) v[i] = s.charCodeAt(i);
return [v, b];
}
onmessage = function (oEvent) {
var v;
try {
v = XLSX.read(ab2str(oEvent.data), {type: 'binary'});
} catch(e) { postMessage({t:"e",d:e.stack}); }
var res = {t:"xlsx", d:JSON.stringify(v)};
var r = s2ab(res.d)[1];
postMessage(r, [r]);
};

29
xlsxworker2.js Normal file

@ -0,0 +1,29 @@
/* xlsx.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('jszip.js');
importScripts('xlsx.js');
postMessage({t:"ready"});
function ab2str(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint16Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint16Array(data.slice(l*w)));
return o;
}
function s2ab(s) {
var b = new ArrayBuffer(s.length*2), v = new Uint16Array(b);
for (var i=0; i != s.length; ++i) v[i] = s.charCodeAt(i);
return [v, b];
}
onmessage = function (oEvent) {
var v;
try {
v = XLSX.read(ab2str(oEvent.data), {type: 'binary'});
} catch(e) { postMessage({t:"e",d:e.stack}); }
var res = {t:"xlsx", d:JSON.stringify(v)};
var r = s2ab(res.d)[1];
postMessage(r, [r]);
};