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>
|
2022-04-06 06:45:11 +00:00
|
|
|
<meta charset="utf-8" />
|
2017-02-24 05:11:45 +00:00
|
|
|
<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%;
|
|
|
|
}
|
2017-08-09 06:50:59 +00:00
|
|
|
a { text-decoration: none }
|
2014-05-20 17:43:03 +00:00
|
|
|
</style>
|
2017-02-24 05:11:45 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2017-08-09 06:50:59 +00:00
|
|
|
<pre>
|
|
|
|
<b><a href="http://sheetjs.com">SheetJS CFB Preview Live Demo</a></b>
|
2014-05-20 17:43:03 +00:00
|
|
|
|
2017-08-09 06:50:59 +00:00
|
|
|
<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>
|
2014-05-20 17:43:03 +00:00
|
|
|
<div id="drop">Drop an XLS file here to see the CFB structure.</div>
|
2017-08-09 06:50:59 +00:00
|
|
|
|
|
|
|
<b>Advanced Demo Options:</b>
|
|
|
|
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
|
2017-09-20 23:33:03 +00:00
|
|
|
|
2018-09-04 07:14:20 +00:00
|
|
|
<b>Export Current File</b>
|
2020-07-09 06:12:05 +00:00
|
|
|
- <a id="savecfb" onclick="savefile('cfb');" href="#">Export data as CFB</a> (Container File Binary Format)
|
2018-09-04 07:14:20 +00:00
|
|
|
- <a id="savezip" onclick="savefile('zip');" href="#">Export data as ZIP</a>
|
2020-07-09 06:12:05 +00:00
|
|
|
- <a id="savemad" onclick="savefile('mad');" href="#">Export data as MAD</a> (MIME aggregate document)
|
2017-08-09 06:50:59 +00:00
|
|
|
</pre>
|
2014-05-20 17:43:03 +00:00
|
|
|
<pre id="out"></pre>
|
|
|
|
<br />
|
2017-09-28 06:20:50 +00:00
|
|
|
<script src="shim.js"></script>
|
|
|
|
<script src="https://unpkg.com/printj/dist/printj.min.js"></script>
|
2022-04-06 06:45:11 +00:00
|
|
|
<script src="dist/cfb.min.js"></script>
|
2014-05-20 17:43:03 +00:00
|
|
|
<script>
|
2017-02-24 05:11:45 +00:00
|
|
|
/*jshint browser:true */
|
2017-08-09 06:50:59 +00:00
|
|
|
/* eslint-env browser */
|
2020-03-13 05:58:41 +00:00
|
|
|
/*global Uint8Array, ArrayBuffer */
|
2022-04-06 06:45:11 +00:00
|
|
|
/*global CFB, out, PRINTJ */
|
2018-01-19 01:09:51 +00:00
|
|
|
/* exported savefile, download_file */
|
2017-08-09 06:50:59 +00:00
|
|
|
/* eslint no-use-before-define:0 */
|
2017-09-20 23:33:03 +00:00
|
|
|
var global_cfb;
|
2017-02-24 05:11:45 +00:00
|
|
|
|
2021-09-06 19:53:23 +00:00
|
|
|
if(!String.prototype.repeat) String.prototype.repeat = function(count) {
|
|
|
|
var o = "";
|
|
|
|
for(var i = 0; i < count; ++i) o += this;
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
2017-09-20 23:33:03 +00:00
|
|
|
var get_manifest = (function() {
|
|
|
|
var sprintf = PRINTJ.sprintf;
|
|
|
|
function fix_string(x/*:string*/)/*:string*/ { return x.replace(/[\u0000-\u001f]/, function($$) { return sprintf("\\u%04X", $$.charCodeAt(0)); }); }
|
2017-08-09 06:50:59 +00:00
|
|
|
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());
|
|
|
|
};
|
2017-09-20 23:33:03 +00:00
|
|
|
return function get_manifest(cfb) {
|
|
|
|
var out = [];
|
2018-09-04 07:14:20 +00:00
|
|
|
var rlen = cfb.FullPaths[0].length;
|
2017-08-09 06:50:59 +00:00
|
|
|
|
2017-09-20 23:33:03 +00:00
|
|
|
var basetime = new Date(1980,0,1);
|
|
|
|
var cnt = 0, rootsize = 0, filesize = 0;
|
|
|
|
out.push(" Length Date Time Name");
|
|
|
|
out.push(" -------- ---- ---- ----");
|
2017-10-20 20:36:54 +00:00
|
|
|
cfb.FileIndex.forEach(function(file/*:CFBEntry*/, i/*:number*/) {
|
2017-09-20 23:33:03 +00:00
|
|
|
switch(file.type) {
|
|
|
|
case 5:
|
|
|
|
basetime = file.ct || file.mt || basetime;
|
|
|
|
rootsize = file.size;
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-09-04 07:14:20 +00:00
|
|
|
var fixname = fix_string(cfb.FullPaths[i]);
|
|
|
|
if(fixname.match(/\\u0001Sh33tJ5/)) return;
|
|
|
|
fixname = fixname.slice(rlen);
|
|
|
|
out.push(sprintf("%9lu %s <a href=\"#\" onclick=\"download_file(%d);\">%s</a>", file.size, format_date(basetime), i, fixname));
|
2017-09-20 23:33:03 +00:00
|
|
|
filesize += file.size;
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
out.push(" -------- -------");
|
|
|
|
out.push(sprintf("%9lu %lu file%s", rootsize || filesize, cnt, (cnt !== 1 ? "s" : "")));
|
|
|
|
return out.join("\n");
|
|
|
|
};
|
|
|
|
})();
|
2017-08-09 06:50:59 +00:00
|
|
|
|
|
|
|
function process_data(cfb) {
|
2017-09-20 23:33:03 +00:00
|
|
|
global_cfb = cfb;
|
2017-08-09 06:50:59 +00:00
|
|
|
var output = get_manifest(cfb);
|
2017-10-20 20:36:54 +00:00
|
|
|
out.innerHTML = output;
|
2014-05-20 17:43:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 23:33:03 +00:00
|
|
|
var do_file = (function() {
|
|
|
|
var rABS = typeof FileReader !== "undefined" && (FileReader.prototype||{}).readAsBinaryString;
|
|
|
|
var domrabs = document.getElementsByName("userabs")[0];
|
|
|
|
if(!rABS) domrabs.disabled = !(domrabs.checked = false);
|
|
|
|
|
|
|
|
return function do_file(files) {
|
|
|
|
rABS = domrabs.checked;
|
|
|
|
var f = files[0];
|
2014-05-20 17:43:03 +00:00
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var data = e.target.result;
|
2021-09-06 19:53:23 +00:00
|
|
|
var cfb = CFB.read(rABS ? data : new Uint8Array(data), {type: rABS ? 'binary' : 'buffer'});
|
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);
|
2017-09-20 23:33:03 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var drop = document.getElementById('drop');
|
|
|
|
if(!drop.addEventListener) return;
|
|
|
|
|
|
|
|
function handleDrop(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
do_file(e.dataTransfer.files);
|
2014-05-20 17:43:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 23:33:03 +00:00
|
|
|
function handleDragover(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
|
|
}
|
2014-05-20 17:43:03 +00:00
|
|
|
|
|
|
|
drop.addEventListener('dragenter', handleDragover, false);
|
|
|
|
drop.addEventListener('dragover', handleDragover, false);
|
|
|
|
drop.addEventListener('drop', handleDrop, false);
|
2017-09-20 23:33:03 +00:00
|
|
|
})();
|
|
|
|
|
2022-04-06 06:45:11 +00:00
|
|
|
function saveAs(blob, fname) {
|
|
|
|
var url = URL.createObjectURL(blob);
|
|
|
|
var a = document.createElement("a");
|
|
|
|
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
|
|
|
|
/*:: if(document.body == null) throw new Error("unreachable"); */ document.body.removeChild(a);
|
|
|
|
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
|
|
|
}
|
|
|
|
|
2017-09-20 23:33:03 +00:00
|
|
|
var savefile = (function() {
|
|
|
|
var s2ab = function s2ab(s) {
|
|
|
|
var buf, i=0;
|
|
|
|
if(typeof ArrayBuffer !== 'undefined') {
|
|
|
|
buf = new ArrayBuffer(s.length);
|
|
|
|
var view = new Uint8Array(buf);
|
|
|
|
for (; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
|
|
|
|
return buf;
|
|
|
|
} else {
|
|
|
|
buf = new Array(s.length);
|
|
|
|
for (; i!=s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-04 07:14:20 +00:00
|
|
|
return function savefile(type) {
|
2017-09-20 23:33:03 +00:00
|
|
|
if(!global_cfb) return alert("Must load a file first!");
|
2018-03-05 03:49:40 +00:00
|
|
|
if(typeof console !== 'undefined') console.log(global_cfb);
|
2018-09-04 07:14:20 +00:00
|
|
|
var data = CFB.write(global_cfb, {type:'binary', fileType: type});
|
2018-03-05 03:49:40 +00:00
|
|
|
if(typeof console !== 'undefined') console.log(data);
|
2022-04-06 06:45:11 +00:00
|
|
|
var newcfb = CFB.read(data, {type:'binary'});
|
|
|
|
console.log(newcfb);
|
2021-09-06 19:53:23 +00:00
|
|
|
|
|
|
|
var fname = "SheetJSCFBDemo." + type;
|
|
|
|
var blob = new Blob([s2ab(data)],{type:"application/octet-stream"});
|
|
|
|
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
|
|
|
|
saveAs(blob, fname);
|
2017-09-20 23:33:03 +00:00
|
|
|
};
|
|
|
|
})();
|
2017-10-20 20:36:54 +00:00
|
|
|
|
|
|
|
var download_file = (function() {
|
|
|
|
var a2ab = function a2ab(a) {
|
|
|
|
var o = new ArrayBuffer(a.length);
|
|
|
|
var view = new Uint8Array(o);
|
|
|
|
for (var i = 0; i!=a.length; ++i) view[i] = a[i];
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
|
|
|
return function download_file(i) {
|
|
|
|
if(!global_cfb) return alert("Must load a file first!");
|
2018-03-05 03:49:40 +00:00
|
|
|
if(typeof console !== 'undefined') console.log(global_cfb);
|
2017-10-20 20:36:54 +00:00
|
|
|
var file = global_cfb.FileIndex[i], data = file.content;
|
2022-04-06 06:45:11 +00:00
|
|
|
var blob = new Blob([a2ab(data)],{type:"application/octet-stream"});
|
|
|
|
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, file.name);
|
|
|
|
saveAs(blob, file.name);
|
2017-10-20 20:36:54 +00:00
|
|
|
};
|
|
|
|
})();
|
2017-08-09 06:50:59 +00:00
|
|
|
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>
|
2017-02-24 05:11:45 +00:00
|
|
|
</body>
|
|
|
|
</html>
|