2014-05-20 17:43:03 +00:00
|
|
|
<!DOCTYPE html>
|
2017-02-24 05:11:45 +00:00
|
|
|
<!-- cfb.js (C) 2013-present SheetJS http://sheetjs.com -->
|
|
|
|
<!-- vim: set ts=2: -->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
|
|
<title>JS-CFB Live Demo</title>
|
2014-05-20 17:43:03 +00:00
|
|
|
<style>
|
|
|
|
#drop{
|
|
|
|
border:2px dashed #bbb;
|
|
|
|
-moz-border-radius:5px;
|
|
|
|
-webkit-border-radius:5px;
|
|
|
|
border-radius:5px;
|
|
|
|
padding:25px;
|
|
|
|
text-align:center;
|
|
|
|
font:20pt bold,"Vollkorn";color:#bbb
|
|
|
|
}
|
|
|
|
#b64data{
|
|
|
|
width:100%;
|
|
|
|
}
|
|
|
|
</style>
|
2017-02-24 05:11:45 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2014-05-20 17:43:03 +00:00
|
|
|
<b>JS-CFB Live Demo</b><br />
|
|
|
|
|
|
|
|
<div id="drop">Drop an XLS file here to see the CFB structure.</div>
|
2017-02-24 05:11:45 +00:00
|
|
|
Advanced Demo Options: <br />
|
|
|
|
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked><br />
|
2014-05-20 17:43:03 +00:00
|
|
|
<pre id="out"></pre>
|
|
|
|
<br />
|
|
|
|
<script src="cfb.js"></script>
|
|
|
|
<script>
|
2017-02-24 05:11:45 +00:00
|
|
|
/*jshint browser:true */
|
|
|
|
/*global CFB, out */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(l*w)));
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2014-05-20 17:43:03 +00:00
|
|
|
function process_data(data) {
|
|
|
|
if(out.innerText === undefined) out.textContent = data.FullPaths;
|
|
|
|
else out.innerText = data.FullPaths.join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
var drop = document.getElementById('drop');
|
|
|
|
function handleDrop(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2017-02-24 05:11:45 +00:00
|
|
|
rABS = document.getElementsByName("userabs")[0].checked;
|
2014-05-20 17:43:03 +00:00
|
|
|
var files = e.dataTransfer.files;
|
2017-02-24 05:11:45 +00:00
|
|
|
var f = files[0];
|
|
|
|
{
|
2014-05-20 17:43:03 +00:00
|
|
|
var reader = new FileReader();
|
2017-02-24 05:11:45 +00:00
|
|
|
//var name = f.name;
|
2014-05-20 17:43:03 +00:00
|
|
|
reader.onload = function(e) {
|
|
|
|
var data = e.target.result;
|
2017-02-24 05:11:45 +00:00
|
|
|
var cfb;
|
|
|
|
if(rABS) {
|
|
|
|
cfb = CFB.read(data, {type: 'binary'});
|
|
|
|
} else {
|
|
|
|
var arr = fixdata(data);
|
|
|
|
cfb = CFB.read(btoa(arr), {type: 'base64'});
|
|
|
|
}
|
2014-05-20 17:43:03 +00:00
|
|
|
process_data(cfb);
|
|
|
|
};
|
2017-02-24 05:11:45 +00:00
|
|
|
if(rABS) reader.readAsBinaryString(f);
|
|
|
|
else reader.readAsArrayBuffer(f);
|
2014-05-20 17:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDragover(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(drop.addEventListener) {
|
|
|
|
drop.addEventListener('dragenter', handleDragover, false);
|
|
|
|
drop.addEventListener('dragover', handleDragover, false);
|
|
|
|
drop.addEventListener('drop', handleDrop, false);
|
|
|
|
}
|
|
|
|
</script>
|
2017-02-24 05:11:45 +00:00
|
|
|
</body>
|
|
|
|
</html>
|