default to readAsBinaryString

This commit is contained in:
SheetJS 2013-12-26 00:38:44 -05:00
parent b532159fb2
commit 7c5bc5b20d
2 changed files with 18 additions and 10 deletions

@ -1,4 +1,5 @@
<!DOCTYPE html>
<!-- xlsx.js (C) 2013 SheetJS http://sheetjs.com -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@ -35,17 +36,18 @@
<script src="xlsx.js"></script>
<script src="shim.js"></script>
<script>
var rABS = typeof FileReader.prototype.readAsBinaryString !== "undefined";
function xlsxworker(data, cb) {
var worker = new Worker('./xlsxworker.js');
worker.onmessage = function(e) {
switch(e.data.t) {
case 'ready': break;
case 'e': console.error(e.data.d);
case 'e': console.error(e.data.d); break;
case 'xlsx': cb(JSON.parse(e.data.d)); break;
}
};
var arr = btoa(String.fromCharCode.apply(null, new Uint8Array(data)));
worker.postMessage(arr);
var arr = rABS ? data : btoa(String.fromCharCode.apply(null, new Uint8Array(data)));
worker.postMessage({d:arr,b:rABS});
}
function get_radio_value( radioName ) {
@ -130,14 +132,18 @@ function handleDrop(e) {
if(typeof Worker !== 'undefined') {
xlsxworker(data, process_wb);
} else {
//var wb = XLSX.read(data, {type: 'binary'});
var arr = String.fromCharCode.apply(null, new Uint8Array(data));
var wb = XLSX.read(btoa(arr), {type: 'base64'});
process_wb(wb);
var wb;
if(rABS) {
wb = XLSX.read(data, {type: 'binary'});
} else {
var arr = String.fromCharCode.apply(null, new Uint8Array(data));
wb = XLSX.read(btoa(arr), {type: 'base64'});
}
process_wb(wb);
}
};
//reader.readAsBinaryString(f);
reader.readAsArrayBuffer(f);
if(rABS) reader.readAsBinaryString(f);
else reader.readAsArrayBuffer(f);
}
}

@ -1,3 +1,4 @@
/* xlsx.js (C) 2013 SheetJS -- http://sheetjs.com */
importScripts('jszip.js');
importScripts('xlsx.js');
postMessage({t:"ready"});
@ -5,7 +6,8 @@ postMessage({t:"ready"});
onmessage = function (oEvent) {
var v;
try {
v = XLSX.read(oEvent.data, {type: 'base64'});
//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}); }
postMessage({t:"xlsx", d:JSON.stringify(v)});
};