js-cfb/index.html
SheetJS 1a428c8f5b version bump 0.10.3: ignore bad FAT
- sector checked before reading (h/t @e12009)
  See https://github.com/SheetJS/js-xlsx/issues/569
- flow type checking
2017-02-23 21:11:45 -08:00

93 lines
2.4 KiB
HTML

<!DOCTYPE html>
<!-- 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>
<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>
</head>
<body>
<b>JS-CFB Live Demo</b><br />
<div id="drop">Drop an XLS file here to see the CFB structure.</div>
Advanced Demo Options: <br />
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked><br />
<pre id="out"></pre>
<br />
<script src="cfb.js"></script>
<script>
/*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;
}
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();
rABS = document.getElementsByName("userabs")[0].checked;
var files = e.dataTransfer.files;
var f = files[0];
{
var reader = new FileReader();
//var name = f.name;
reader.onload = function(e) {
var data = e.target.result;
var cfb;
if(rABS) {
cfb = CFB.read(data, {type: 'binary'});
} else {
var arr = fixdata(data);
cfb = CFB.read(btoa(arr), {type: 'base64'});
}
process_data(cfb);
};
if(rABS) reader.readAsBinaryString(f);
else reader.readAsArrayBuffer(f);
}
}
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>
</body>
</html>