Worker HTML update

This commit is contained in:
SheetJS 2014-02-17 16:45:37 -05:00
parent 7581648544
commit ec3cf450ad
2 changed files with 40 additions and 3 deletions

@ -1,5 +1,6 @@
<!DOCTYPE html>
<!-- xlsx.js (C) 2013-2014 SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@ -37,6 +38,14 @@
<script src="shim.js"></script>
<script>
var rABS = typeof FileReader !== "undefined" && typeof FileReader.prototype !== "undefined" && typeof FileReader.prototype.readAsBinaryString !== "undefined";
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)));
return o;
}
function xlsxworker(data, cb) {
var worker = new Worker('./xlsxworker.js');
worker.onmessage = function(e) {
@ -46,7 +55,7 @@ function xlsxworker(data, cb) {
case 'xlsx': cb(JSON.parse(e.data.d)); break;
}
};
var arr = rABS ? data : btoa(String.fromCharCode.apply(null, new Uint8Array(data)));
var arr = rABS ? data : btoa(fixdata(data));
worker.postMessage({d:arr,b:rABS});
}
@ -110,7 +119,7 @@ function process_wb(wb) {
break;
case "form":
output = to_formulae(wb);
break;
break;
default:
output = to_csv(wb);
}
@ -136,7 +145,7 @@ function handleDrop(e) {
if(rABS) {
wb = XLSX.read(data, {type: 'binary'});
} else {
var arr = String.fromCharCode.apply(null, new Uint8Array(data));
var arr = fixdata(data);
wb = XLSX.read(btoa(arr), {type: 'base64'});
}
process_wb(wb);

28
shim.js

@ -143,3 +143,31 @@ if (!Array.prototype.map) {
return A;
};
}
// https://github.com/ttaubert/node-arraybuffer-slice
// (c) 2013 Tim Taubert <tim@timtaubert.de>
// arraybuffer-slice may be freely distributed under the MIT license.
"use strict";
if (!ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
begin = (begin|0) || 0;
var num = this.byteLength;
end = end === (void 0) ? num : (end|0);
// Handle negative values.
if (begin < 0) begin += num;
if (end < 0) end += num;
if (num === 0 || begin >= num || begin >= end) {
return new ArrayBuffer(0);
}
var length = Math.min(num - begin, end - begin);
var target = new ArrayBuffer(length);
var targetArray = new Uint8Array(target);
targetArray.set(new Uint8Array(this, begin, length));
return target;
};
}