forked from sheetjs/sheetjs
added file input to web demo
This commit is contained in:
parent
cb1dd13e45
commit
dbebd21d5e
38
index.html
38
index.html
@ -34,7 +34,8 @@ Output Format:
|
||||
<input type="radio" name="format" value="json"> JSON<br>
|
||||
<input type="radio" name="format" value="form"> FORMULAE<br> -->
|
||||
|
||||
<div id="drop">Drop an XLSX or XLSM or XLSB file here to see sheet data.</div>
|
||||
<div id="drop">Drop an XLSX or XLSM or XLSB file here to see sheet data</div>
|
||||
<p><input type="file" name="xlfile" id="xlf" /> ... or click here to select a file</p>
|
||||
<textarea id="b64data">... or paste a base64-encoding here</textarea>
|
||||
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
|
||||
Advanced Demo Options: <br />
|
||||
@ -182,7 +183,7 @@ function process_wb(wb) {
|
||||
var output = "";
|
||||
switch(get_radio_value("format")) {
|
||||
case "json":
|
||||
output = JSON.stringify(to_json(wb), 2, 2);
|
||||
output = JSON.stringify(to_json(wb), 2, 2);
|
||||
break;
|
||||
case "form":
|
||||
output = to_formulae(wb);
|
||||
@ -238,6 +239,39 @@ if(drop.addEventListener) {
|
||||
drop.addEventListener('dragover', handleDragover, false);
|
||||
drop.addEventListener('drop', handleDrop, false);
|
||||
}
|
||||
|
||||
|
||||
var xlf = document.getElementById('xlf');
|
||||
function handleFile(e) {
|
||||
rABS = document.getElementsByName("userabs")[0].checked;
|
||||
use_worker = document.getElementsByName("useworker")[0].checked;
|
||||
var files = e.target.files;
|
||||
var i,f;
|
||||
for (i = 0, f = files[i]; i != files.length; ++i) {
|
||||
var reader = new FileReader();
|
||||
var name = f.name;
|
||||
reader.onload = function(e) {
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
|
||||
var data = e.target.result;
|
||||
if(use_worker) {
|
||||
xlsxworker(data, process_wb);
|
||||
} else {
|
||||
var wb;
|
||||
if(rABS) {
|
||||
wb = XLSX.read(data, {type: 'binary'});
|
||||
} else {
|
||||
var arr = fixdata(data);
|
||||
wb = XLSX.read(btoa(arr), {type: 'base64'});
|
||||
}
|
||||
process_wb(wb);
|
||||
}
|
||||
};
|
||||
if(rABS) reader.readAsBinaryString(f);
|
||||
else reader.readAsArrayBuffer(f);
|
||||
}
|
||||
}
|
||||
|
||||
if(xlf.addEventListener) xlf.addEventListener('change', handleFile, false);
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
|
Loading…
Reference in New Issue
Block a user