js-cfb/index.html
SheetJS 2d0c71ac88 version bump 0.12.1: CFB.find
- exported object includes static find method
- CLI option displays file manifest
- ignore mid-table free sectors
- ignore lazily-deleted files (orphan nodes)
2017-08-09 02:50:59 -04:00

145 lines
4.2 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%;
}
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS CFB Preview Live Demo</a></b>
<a href="https://github.com/SheetJS/js-cfb">Source Code Repo</a>
<a href="https://github.com/SheetJS/js-cfb/issues">Issues? Something look weird? Click here and report an issue</a>
<div id="drop">Drop an XLS file here to see the CFB structure.</div>
<b>Advanced Demo Options:</b>
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
</pre>
<pre id="out"></pre>
<br />
<script src="https://unpkg.com/printj@1.1.0/dist/printj.min.js"></script>
<script src="cfb.js"></script>
<script>
/*jshint browser:true */
/* eslint-env browser */
/* eslint no-use-before-define:0 */
/*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 get_manifest(cfb) {
var out = [];
var sprintf = PRINTJ.sprintf;
var format_date = function(date/*:Date*/)/*:string*/ {
return sprintf("%02u-%02u-%02u %02u:%02u", date.getUTCMonth()+1, date.getUTCDate(), date.getUTCFullYear()%100, date.getUTCHours(), date.getUTCMinutes());
};
var basetime = new Date(1980,0,1);
var cnt = 0;
var rootsize = 0, filesize = 0;
out.push(" Length Date Time Name");
out.push(" -------- ---- ---- ----");
cfb.FileIndex.forEach(function(file, i) {
switch(file.type) {
case 5:
basetime = file.ct || file.mt || basetime;
rootsize = file.size;
break;
case 2:
out.push(sprintf("%9lu %s %s", file.size, format_date(basetime), cfb.FullPaths[i]));
filesize += file.size;
++cnt;
}
});
out.push(" -------- -------");
out.push(sprintf("%9lu %lu file%s", rootsize || filesize, cnt, (cnt !== 1 ? "s" : "")));
return out.join("\n");
}
function process_data(cfb) {
var output = get_manifest(cfb);
if(out.innerText === undefined) out.textContent = output
else out.innerText = output;
}
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>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>